Posts

Design simple arithmetic Calculator using Grid Layout manager.

  // Simple Caluculatorusing Grid Layout import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code = "SimpleCalc" Width=400 height=300> </applet> */ public class SimpleCalc extends Applet implements ActionListener {     int v1,v2,result,i;     TextField t;     Button b[] = new Button [ 10 ];     Button add,sub,mul,div,mod,clear,eq;     char op;         public void init()     {     GridLayout g = new GridLayout( 4 , 5 );     setLayout(g);         t = new TextField( 10 );     for (i= 0 ;i<= 9 ;i++)     {          b[i] = new Button( "" +i);     }     add = new Button( "+" );     sub = new Button( "-" );     mul = new Button( "*" );     div = new Button( "/" );     mod = new Button( "%" );    ...

Design GUI to handle Choice Control event.

  /* Write an applete code to demonstrate usgae of choice control */ import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="ChoiceDemo" width=300 height=100> </applet> */       public class ChoiceDemo extends Applet implements ItemListener {     Choice c1,c2;     public void init()     {     c1 = new Choice();     c2 = new Choice();         // add items to first choce controls     c1.add( "Windows XP" );     c1.add( "Windows 8" );     c1.add( "Windows 10" );     c1.add( "Ubuntu" );     // add items to second choce controls     c2.add( "Google Chrome" );     c2.add( "Mozila Firefox" );     c2.add( "Opera" );     // adding choice controls to applet window     add(c1);     add(c2);     //regisre with event listeners     c...

Display the position of x and y co-ordinates of the cursor movement using mouse

  import java.awt.*;   import java.awt.event.*;   public class Mouse extends Frame implements MouseListener{       Label l;       Mouse(){           addMouseListener( this );                     l= new Label();           l.setBounds( 20 , 50 , 100 , 20 );           add(l);           setSize( 300 , 300 );           setLayout( null );           setVisible( true );       }       public void mouseClicked( MouseEvent e) {           l.setText( "Mouse Clicked" );       }       public void mouseEntered( MouseEvent e) {           l.setText( "Mouse Entered" );       }       public void mouseExited( Mous...

Handle keyboard events, which echoes keystrokes to the applet window and shows the status of each key event in the status bar.

  /* Demonstrate the key event handlers   02-10-2017 */ import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="SimpleKey" width=400 height=200> </applet> */ public class SimpleKey extends Applet implements KeyListener {     String msg = "" ;     int X = 10 , Y = 20 ; // output coordinates     public void init()     {         addKeyListener( this );         //requestFocus();     }     public void keyPressed( KeyEvent ke)     {         showStatus( "Key Down" );     }     public void keyReleased( KeyEvent ke)     {         showStatus( "Key Up" );     }             public void keyTyped( KeyEvent ke)     {         msg += ke.getKeyChar();         repaint(); ...

Create three threads- with different priorities – MAX, MIN, NORM- and start the threads at the same time. Observe the completion of the threads.

  /* Threads Priorities 30-12-2021 */ import java.lang.*;     public class ThreadPriorityDemo extends Thread   {       public void run()       {       System.out.println( "Inside run : " +Thread.currentThread().getName() + " : " +Thread.currentThread().getPriority());       }         public static void main( String args[])       {       ThreadPriorityDemo th1 = new ThreadPriorityDemo();       ThreadPriorityDemo th2 = new ThreadPriorityDemo();       ThreadPriorityDemo th3 = new ThreadPriorityDemo();     th1.setName( "First" );     th2.setName( "Second" );     th3.setName( "Third" );         th1.setPriority(MIN_PRIORITY);       th2.setPriority(NORM_PRIORITY);       th3.setPriority(MAX_PRIORITY);     th1.start();     t...

Create three threads (by using Thread class and Runnable interface) where the first thread displays “Good Morning” every one second, the second thread displays “Hello” every two seconds and the third thread displays “Welcome” every three seconds.

  class NewThread implements Runnable {     String name,m; // name of thread         int st;     NewThread( String threadname, String msg, int time)     {           name = threadname;         m=msg;         st=time;         Thread t = new Thread( this , name);         System.out.println( "New thread: " + t);         t.start();           // Start the thread     }     // This is the entry point for thread.     public void run()     {         try         {             for (i= 0 ;i< 10 ;i++)             {                 System.out.println(m);               ...

Write a java program to create three userdefined exceptions and throw the exceptions using throw and write appropriate catch and finally blocks to handle.

  /* Userdefine Exceptions 28-12-2021 */ import java.util.*; class WrongBranchCodeExcetion extends Exception {     WrongBranchCodeExcetion( String s1)     {     super (s1);     } } class WrongBranchNameExcetion extends Exception {     WrongBranchNameExcetion( String s2)     {     super (s2);     } } class WrongRollNumberExcetion extends Exception {     WrongRollNumberExcetion( String s3)     {     super (s3);     } } class UserDefinedException_5B {     public static void main( String args[])       {       try         {           int b;           Scanner s = new Scanner(System.in);          System.out.print( "Enter Branch Code : " );          b = s.nextInt();         ...

Handle the following exceptions using exception handling mechanism in java. (Note: Handle all exceptions in single program using command line arguments) a. ArithmeticException b. ArrayIndexOutOfBoundsException c. NullPointerException d. IOException e. NumberFormatException

  /* To Handle all exceptions in single program using command line arguments */ import java.util.*; import java.lang.*; class ExceptionHandling_5A {     public static void main( String args[])     {     try     {       int a,c,d,x;               // ArithmeticException         a = Integer.parseInt(args[ 0 ]);       x = 36 /a;       System.out.println( "Division result is : " +x);             // ArrayIndexOutOfBoundsException       int b[] = new int [ 10 ];       b[a] = Integer.parseInt(args[ 1 ]);       System.out.println( "Element in array : " +b[a]);       // NumberFormatException       c = Integer.parseInt(args[ 2 ]);       System.out.println( "Given number is : " +c);       // StringIndexOutOfBound...

Create and access a user defined package where the package contains a class named CircleDemo, which in turn contains a method called circleArea() which takes radius of the circle as the parameter and returns the area of the circle.

5B.zip https://www.mediafire.com/file/gsob5qcj0p8yyf7/5B.zip/file https://www15.zippyshare.com/v/0uoUVlae/file.html

Write an interface called Playable, with a methodvoid play(); Let this interface be placed in a package called music. Write a class called Veena which implements Playable interface. Let this class be placed in a package music.string Write a class called Saxophone which implements Playable interface. Let this class be placed in a package music.wind Write another class Test in a package called live. Then, a. Create an instance of Veena and call play() method b. Create an instance of Saxophone and call play() method c. Place the above instances in a variable of type Playable and then call play()

5A.zip https://www.mediafire.com/file/edoatbqbhs8qf5y/5A.zip/file https://www86.zippyshare.com/v/WVQ0RWtj/file.html

You are supposed to calculate the area of a polygon based on number of inputs given bythe user. Polygon can be a square, a rectangle or a triangle.

 /* Area of a polygon based on number of inputs given by the user */ import java.io.*; import java.util.*; class Polygon {    void area(double a)    { System.out.println("Area of Square = " + a*a);    }    void area(double l,double b)    { System.out.println("Area of Rectangle = " + l*b);    }    void area(double a,double b,double c)    { double s = (a+b+c)/2; double d = s*(s-a)*(s-b)*(s-c); System.out.println("Area of Triangle = " + String.format("%.2f",Math.sqrt(d)));    } } class PolygonArea_4B {     public static void main(String args[])     { Polygon p = new Polygon(); Scanner s = new Scanner(System.in); System.out.print("Enter side of a square : "); double a = s.nextDouble(); p.area(a); System.out.print("Enter sides of a rectangle : "); double l = s.nextDouble(); double b = s.nextDouble(); p.area(l,b); System.out.print("Enter three sides ...

Create an abstract class named shape, that contains an empty method named numberOfSides(). Define three classes named Trapezoid, Triangle and Hexagon, such that each one of the classes contains only the method numberOfSides(), that contains the number of sides in the given geometrical figure.

 /* Abstract classes 25-11-2022 */ abstract class Shape {      abstract void noofsides(); } class Trapezoid extends Shape {      void noofsides()      {     System.out.println("Trapezoid had 4 sides");      } } class Triangle extends Shape {      void noofsides()      {     System.out.println("Triangle had 3 sides");      } } class Hexagon extends Shape {      void noofsides()      {     System.out.println("Hexagon had 6 sides");      } } class Abstract_Noofsides_4A {   public static void main(String args[])   { Trapezoid tr = new Trapezoid(); tr.noofsides(); Triangle t = new Triangle(); t.noofsides(); Hexagon h = new Hexagon(); h.noofsides();   } }

Access the instance variables by using „this‟ and super keywords.

 /* Access the instance variables by using super keywords */ import java.io.*; import java.util.*; class A {    int i=10,j;    void showij()    { System.out.println("In class A, i = "+i+" and j = "+j);    } } class B extends A {    int i,k;    void showik()    { System.out.println("In class A, i = "+super.i); System.out.println("In class B, i = "+i+" and k = "+k);    } } class Super_Overriding_3B {    public static void main(String args[])    { Scanner s = new Scanner(System.in);     A obj1 = new A();     System.out.print("Enter i value : ");     obj1.i = s.nextInt();     System.out.print("Enter j value : ");     obj1.j = s.nextInt(); obj1.showij();     B obj2 = new B();     System.out.print("Enter i value for class B : ");     obj2.i = s.nextInt();     System.out.pri...

Tom and Jerry found two bags of apples. The bag that Jerry chose contains 5 apples and the bag chosen by Tom has 3 apples. Tom wants to have more apples, so he swaps the bags. Write a program to display the apples in the two bags before and after swapping. Hint :-( Try using call by value and call by reference; Write which can be used to swap)

 /* Swap two numbers using Pass by object */ import java.io.*; import java.util.*; class Swap_Obj_3A {     public static void main(String args[])     { Test te = new Test(); System.out.println("Enter a Value : "); Scanner s = new Scanner(System.in); te.a = s.nextInt(); System.out.println("Enter b Value : "); te.b = s.nextInt(); te.swap(te);     } } class Test {     int a,b,t;     void swap(Test te)     { System.out.println("Before swapping a = "+te.a+" and b = "+te.b); t = te.a; te.a = te.b; te.b = t; System.out.println("After swapping a = "+te.a+" and b = "+te.b);     } } ----------------------------------------------------------------------------------------------------------------------------- /* Swap two numbers using Pass by value */ import java.io.*; import java.util.*; class Swap_Obj_3A2 {     public static void main(String args[])     { Test te = new Tes...

You are given a string consisting of n lowercase Latin letters. You must find the count of number of larger alphabets for every character of the string (according to lexicographical order).

 /* Counting no.of larger alphabets for every character of the string */ import java.io.*; import java.util.*; class Alpha_2B {     public static void main(String args[])     { String s1; int i,j,c,n; int a[] = new int[20]; Scanner s = new Scanner(System.in); System.out.println("Enter  a string : "); s1 = s.next(); n = s1.length(); char t; char ch[] = s1.toCharArray();   // Converting String to charecter array // Sorting charecters for(i=0;i<n;i++) {    for(j=0;j<n;j++)    { if(ch[i] < ch[j]) {    t = ch[i];    ch[i]= ch[j];    ch[j] = t; }    } } // Counting charecter  for(i=0;i<n;i++) {    c=0;    for(j=0;j<n;j++)    { if(ch[i] < ch[j]) {    c++; }    }    a[i] = c; } // Printing sorted charecters System.out.println("Sor...

Software is being developed by a university that displays SGPA of your current semester. You are given the task to develop a module that calculates the SGPA with respect to the secured grade points corresponding to given number of credits in each subject. The credits for the courses are: Graphics: 2, PPS: 4, JAVA: 3, Chemistry: 3, English: 2, Technical Skills: 1.5, Data Structures: 4 Complete your Module by displaying the SGPA of current semester.

 /* Caluculating */ import java.util.*; class SGPA_Cal_S_2A {     public static void main(String[] args)     { Scanner s = new Scanner(System.in); double SGPA,total=0,sum=0; int gp=0,i; String grade; String subjects[]={"Graphics","PPS","JAVA","Chemistry","English","TechnicalSkills","Data Structures"}; double Credits[]={2,4,3,3,2,1.5,4}; for(i=0;i<subjects.length;i++) {       System.out.print("Enter "+subjects[i]+" Grade : ");       grade = s.next();       switch(grade)       { case "A+":gp=10; break; case "A": gp=9; break; case "B": gp=8; break; case "C": gp=7; break; case "D": gp=6; break; case "E": gp=5; break; case "F": gp=0; break; default: System.out.println("Wrong Grade.");   i--;       }       if(gp==0)       { break;       }       t...

Write a Java program that reads an integer number (between 1 and 255) from the user and prints the binary representation of the number. The answer should be printed as a String. Note: The output displayed should contain 8 digits and should be padded with leading 0s(zeros), in case the returned String contains less than 8 characters. For example, if the user enters the value 16, then the output should be 00010000 and if the user enters the value 100, the output should be 01100100 (Hint : You may use String.format() method for the expected output)

 /* Binary Representation of given number */ import java.util.*; class Decimal_Binary_1B { public static void main(String args[]) { Scanner s = new Scanner(System.in); System.out.println("Enter an integer between 1 to 255"); int n=s.nextInt(); if(n<1 || n>255) { System.out.println("Input must enter in between 1 to 255"); } else { String b=String.format("%08d",Integer.valueOf(Integer.toString(n,2))); //Integer.BinaryString(n) System.out.println("Binary value is:"+b); } } }

John found another manuscript of ancient mathematicians. According to this manuscript an integer k is a lucky number if k = a1 + a2 + ... + an, where: ai = 7p. p may be any positive integer. if i and j are distinct, ai != aj For example 7 is a lucky number: 7 = 71. 56 is a lucky number 56 = 72 + 71. John has an array of n integers. He wants to determine how many members of this array are lucky. He is not good at programming and needs your help. Write a program which takes an integer n and array consisting of n integers and determines quantity of lucky integers in this array.

 /* Lucky Number*/ import java.io.*; import java.util.*; import java.lang.*; class Lucky {     public static void main(String args[])     { int i,n,sum=0; int a[] = new int[20]; System.out.println("Enter number of elements : "); Scanner s = new Scanner(System.in); n = s.nextInt(); System.out.println("Enter elements to array : "); for(i=0;i<n;i++) {     a[i] = s.nextInt(); }     LuckyNumber(n,a);     }     public static void LuckyNumber(int n,int a[])     { int i,j,c=0,sum=0; int b[] = new int[20]; for(i=0;i<n;i++) {            sum = 0;    for(j=1;j<8;j++)    {           sum += Math.pow(7,j); if(a[i] == sum) {     b[c] = a[i];     c++;     break; }    } }   System.out.println("Number of Lucky Numbers are : "+c); System.out.pri...