diff --git a/src/A.java b/src/A.java new file mode 100644 index 0000000..42e0766 --- /dev/null +++ b/src/A.java @@ -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[]){ + + + } +} + diff --git a/src/Add.class b/src/Add.class new file mode 100644 index 0000000..4ffd136 Binary files /dev/null and b/src/Add.class differ diff --git a/src/AnnotationBasics.java b/src/AnnotationBasics.java new file mode 100644 index 0000000..098def3 --- /dev/null +++ b/src/AnnotationBasics.java @@ -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(); + } + + +} diff --git a/src/AnnotationJava.java b/src/AnnotationJava.java new file mode 100644 index 0000000..c84cbc4 --- /dev/null +++ b/src/AnnotationJava.java @@ -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--; + } + } +} + + + diff --git a/src/AnotherFrame.java b/src/AnotherFrame.java new file mode 100644 index 0000000..41ed4d4 --- /dev/null +++ b/src/AnotherFrame.java @@ -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(); + + } +} diff --git a/src/CardlayoutDemo.java b/src/CardlayoutDemo.java new file mode 100644 index 0000000..d63acc5 --- /dev/null +++ b/src/CardlayoutDemo.java @@ -0,0 +1,50 @@ +import java.applet.Applet; +import java.awt.*; +//import java.awt.Label; + + + +// +// + +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(); + } + + + + +} diff --git a/src/CompareArray.java b/src/CompareArray.java new file mode 100644 index 0000000..176e9e0 --- /dev/null +++ b/src/CompareArray.java @@ -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(s[j])){ + String temp = s[i]; + s[i] = s[j]; + s[j] = temp; + + } + } + } + + + + //Output + for(int i=0;i