Skip to content

Add files via upload #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0e910e8
Add files via upload
Ramstein Apr 23, 2019
f2504c7
Update MouseEventsDemo.java
Ramstein Apr 23, 2019
5f813cb
Update AnnotationBasics.java
Ramstein Apr 23, 2019
6ea77bc
Update AnnotationJava.java
Ramstein Apr 23, 2019
5553f66
Update AnotherFrame.java
Ramstein Apr 23, 2019
f3903fb
Update CardlayoutDemo.java
Ramstein Apr 23, 2019
97aee16
Update CompareArray.java
Ramstein Apr 23, 2019
137ff40
Update DirDemo.java
Ramstein Apr 23, 2019
ebb48fe
Update DuplicateWords.java
Ramstein Apr 23, 2019
311e1f6
Update EOF.java
Ramstein Apr 23, 2019
4d2ba52
Update FXMLDocumentController.java
Ramstein Apr 23, 2019
1365cb3
Update FileInputStreamDemo.java
Ramstein Apr 23, 2019
1e3e4ae
Update FormattingOutput.java
Ramstein Apr 23, 2019
47c8a66
Update HourGlass.java
Ramstein Apr 23, 2019
8af5a1a
Update GenericsWithTwoTypeParameters.java
Ramstein Apr 23, 2019
c992d26
Update InnerClass.java
Ramstein Apr 23, 2019
70a2cc3
Update IntToString.java
Ramstein Apr 23, 2019
d02e90f
Update JavaClass.java
Ramstein Apr 23, 2019
652a707
Update try_catch.java
Ramstein Apr 23, 2019
d5c2d2b
Update WriteClass.java
Ramstein Apr 23, 2019
214cfcc
Update SwingDemo.java
Ramstein Apr 23, 2019
ddb03c5
Update Solution2.java
Ramstein Apr 23, 2019
789025a
Update Solution1.java
Ramstein Apr 23, 2019
77bf614
Update Solution.java
Ramstein Apr 23, 2019
ed38ed9
Update PrimeChecker.java
Ramstein Apr 23, 2019
4b4e563
Update PaintDemo.java
Ramstein Apr 23, 2019
756dfda
Update NEw.java
Ramstein Apr 23, 2019
d450e95
Update MyFrame.java
Ramstein Apr 23, 2019
dcfa5ea
Update MethodOverriding.java
Ramstein Apr 23, 2019
72006a9
Update MediaTrack.java
Ramstein Apr 23, 2019
7b5d375
Update LambdaExpression.java
Ramstein Apr 23, 2019
30f57e0
Update JavaDateAndTime.java
Ramstein Apr 23, 2019
82612b2
Update JavaInterface.java
Ramstein Apr 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@


//class B extends A{
// static protected int method1(int a, int b){
// return 0;
// }//not

// public int method1(int a , int b){
// return 0;
// }//yes//overrides
//
// public static void main(String args[]){
// method1(5,6);
// }

// private int method1(int a , int b){
// return 0;
// }//not

// public short method1(int a , int b){
// return 0;
// }//Incompatible return type


// private int method1(int a , long b){
// return 0;
// }//yes//overloads}
public class A {

//protected int method1(int a, int b) {
//return 0;
public static void main(String args[]){


}
}

Binary file added src/Add.class
Binary file not shown.
55 changes: 55 additions & 0 deletions src/AnnotationBasics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.lang.reflect.*;
import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@interface MyAnno{
String str();
int val();
}
@Retention(RetentionPolicy.RUNTIME)
@interface what{
String description();
}

@MyAnno(str ="AnnotationBasics Class", val = 621315)
@what(description = "An annotation test example")
public class AnnotationBasics{


@MyAnno(str ="Annotation Example ", val =841655)
@what(description = "An annotation test method.")
public static void myMeth() {//this annotation annotates the myMeth() method
AnnotationBasics annotationBasics = new AnnotationBasics();
try {

Annotation annotation[] = annotationBasics.getClass().getAnnotations();
//class<?> c = annotationBasics.getClass();
//Method method = c.getMethod("myMeth");

//MyAnno myAnn = method.getAnnotation(MyAnno.class);
System.out.println("\nAll annotations for AnnotationBasics class.");

for(Annotation annotation1 : annotation){
System.out.println(annotation1);
}
Method method = annotationBasics.getClass().getMethod("myMeth");
annotation = method.getAnnotations();


System.out.println("\nPrinting all annotations for myMeth().");
for(Annotation annotation1 : annotation){
System.out.println(annotation1);
}


}catch (NoSuchMethodException e){
System.out.println("Method not found.");
}

}
public static void main(String args[]){
myMeth();
}


}
67 changes: 67 additions & 0 deletions src/AnnotationJava.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface FamilyBudget {
String userRole() default "guest";
int budgetLimit() default 100;
}

class FamilyMember {
@FamilyBudget( userRole = "senior", budgetLimit = 100)
public void seniorMember(int budget, int moneySpend) {
System.out.println("Senior Member");
System.out.println("Spend: " + moneySpend);
System.out.println("Budget Left: " + (budget - moneySpend));
}

@FamilyBudget(userRole = "junior", budgetLimit =50)
public void juniorUser(int budget, int moneySpend) {
System.out.println("Junior Member");
System.out.println("Spend: " + moneySpend);
System.out.println("Budget Left: " + (budget - moneySpend));
}
@FamilyBudget(userRole = "guest", budgetLimit = 200)
public void guestUser(int budget, int moneySpend) {
System.out.println("Guest Member");
System.out.println("Spend: " + moneySpend);
System.out.println("Budget Left: " + (budget - moneySpend));
}
}

class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int testCases = Integer.parseInt(in.nextLine());
while (testCases > 0) {
String role = in.next();
int spend = in.nextInt();
try {
Class annotatedClass = FamilyMember.class;
Method[] methods = annotatedClass.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(FamilyBudget.class)) {
FamilyBudget family = method.getAnnotation(FamilyBudget.class);
String userRole = family.userRole();
int budgetLimit = family.budgetLimit();
if (userRole.equals(role)) {
if(spend <= budgetLimit){
method.invoke(FamilyMember.class.newInstance(), budgetLimit, spend);
}else{
System.out.println("Budget Limit Over");
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
testCases--;
}
}
}



18 changes: 18 additions & 0 deletions src/AnotherFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import javax.swing.JFrame;
import javax.swing.JLabel;

class AnotherFrame extends JFrame
{
public AnotherFrame() {
super("Another GUI");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

add(new JLabel("Empty JFrame"));
pack();
setVisible(true);
}
public static void main(String args[]){
new AnotherFrame();

}
}
50 changes: 50 additions & 0 deletions src/CardlayoutDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.applet.Applet;
import java.awt.*;
//import java.awt.Label;



//<applet code ="CardLayout Demo" width = 300 hight = 200>
//</applet>

class CardLayoutDemo extends Applet {

Checkbox Windows7, Windows8, windows10, Android, Mac, Solaris;
Panel osCards;
Frame frame;

CardLayout cardLayout;
Button Windows, Other;
public void init(){
Windows = new Button("Windows");
Other = new Button("Other");

frame = new Frame("HELLO");
frame.add(Windows);
frame.add(Other);

frame.setVisible(true);
frame.setSize(500,500);
cardLayout = new CardLayout();
//osCards = new Panel();
frame.setLayout(cardLayout);

Windows7 = new Checkbox("Windows7", null, true);




}
// public void actionPerformed(ActiveEvent activeEvent){
// if(activeEvent.getSource() == Windows){
// cardLayout.showStatus("Windows");
// }
// }
public static void main(String args[]){
CardLayoutDemo cardLayoutDemo = new CardLayoutDemo();
}




}
33 changes: 33 additions & 0 deletions src/CompareArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.util.Scanner;
class CompareArray{
public static void main(String []args){
//Input
Scanner sc= new Scanner(System.in);
int n=sc.nextInt();
String []s=new String[n+2];
for(int i=0;i<n;i++){
s[i]=sc.next();
}
sc.close();

//Write your code here
for(int i =0;i<n ; i++){
for(int j=1; j<n; j++){
if((Double)s[i] >(s[j])){
String temp = s[i];
s[i] = s[j];
s[j] = temp;

}
}
}



//Output
for(int i=0;i<n;i++)
{
System.out.println(s[i]);
}
}
}
38 changes: 38 additions & 0 deletions src/DirDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.File;

class DirDemo {

public static void main(String args[]){

String dirName = "C:\\";
File f = new File(dirName);
if(f.isDirectory()){

System.out.println(dirName+ " is a directory");

System.out.println("-----------------------Directories of dirName-------------------------");
String s[] = f.list();
for(int i =0; i<s.length; i++){

String pathname= "dirName" + "/" +s[i];
File f1 = new File(pathname);
if(f1.isDirectory()){
System.out.println(s[i]+ " is a directory.");
}else{


System.out.print(s[i]+" is a file");
if(f.isHidden()){
System.out.println(" Hidden File");
}


}
}
}else{
System.out.println(dirName+ " is a File");


}
}
}
66 changes: 66 additions & 0 deletions src/DuplicateWords.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.graalvm.compiler.debug.TTY.printf;


public class DuplicateWords {

public static void main(String[] args) {
int flags =0;
String regex = "/* Write a RegEx matching repeated words here. */";
//Pattern p = Pattern.compile(regex, /* Insert the correct Pattern flag here.*/);
Pattern p = Pattern.compile(regex, flags);
Scanner in = new Scanner(System.in);
int numSentences = Integer.parseInt(in.nextLine());

while (numSentences-- > 0) {
String input = in.nextLine();
char arr[]= input.toCharArray();
String string = checkRepeats(arr);

Matcher m = p.matcher(input);

while (m.find()) {
input = input.replaceAll(regex, "");
}

System.out.println(input);
}

in.close();
}

static String checkRepeats(char sentence[]){
int i = 0, len, words = 0, again = 0;
len = sentence.length;
char wrd[]= new char[20];
char sen[]= new char[20];
for( i=0; i<len; i++){
while (sentence[i] != ' '){
if (sentence[i] == ' '){
words++;
i++;
wrd[i]=sen[i]=sentence[i];
}
for(int j=0;j<i;j++){
if (wrd[i] !=(sen[i])){
break;
}
else
System.out.println("The search word does not exist in the sentence");
}
if (len == 0){
printf("\nRESULTS: Number of words in the text: %d", words);
printf("\nCharacters:%d ", len);
}
else{
printf("\nRESULTS: Number of words: %d", words + 1);
printf("\nCharacters:%d ", len - 1);
}
printf("The search word repeats %d times in the sentence\n", again);
}}

}

Loading