1. Program to assign two integer values to X and Y. Using the „if" statement the output of the program should display a message whether X is greater than Y. class Al_xy { public static void main(String a[]) { int x=10,y=20; if (x>y) { System.out.println("x is greater y"); } else { System.out.println("x is not greater than y"); } } } 2. Program to list the factorial of the numbers 1 to 10. To calculate the factorial value, use while loop. (Hint: Fact of4 = 4*3*2*1) class A2 fact { public static void main(String a[]) { int i=1,n=10,fact=1; while (i<=n) { fact-fact*i; System.out.println("factorial of"+i+"="+fact); i++; } } } 3. Program to find the area and circumference of the circle by accepting the radius from the user. import java.io.*; import java.util.*; class A3 circle { public static void main(String a[]) { float pi-3.142f,area,cir; Scanner sc-new Scanner(System.in); System.out.println("Enter radius of a circle:"); int r=sc.nextInt(); area = pi*r*r; cir = 2*pi*r; System.out.println("Area of circle="+area); System.out.println("Circumference of a circle="+cir); } } 4. Program to add two integers and two float numbers. When no arguments are supplied, give a default value to calculate the sum. Use function overloading. class A4_overload { int x=100,y=200; public static void main(String ar]]) { A4 overload obj=new A4_overload(); obj.add(); System.out.println("Sum of integers="+obj.add(10,20)); System.out.println("Sum of float numbers="+obj.add(10.5f,20.3f)); } void add() { int sum-x+y; System.out.println("Sum of default values="+sum); } int add(int x,int y) { return (x+y); } float add(float x, float y) { return (x+y); } } 5. Program to perform mathematical operations. Create a class called AddSub withmethods to add and subtract. Create another class called MulDiv that extends from AddSub class to use the member data of the super class. MulDiv should have methods to multiply and divide A main function should access the methods and perform the mathematical operations classAddSub { int x-6,y=2; int sum { return(x+y); } int sub) { return(x-y); } } class MulDivextendsAddSub { int mul() { return(x*y); } int div() { return(x/y); } } class mathop { publicstaticvoid main(Stringa[]) { MulDiv obj-new MulDiv(); System.out.println("Sum="+obj.sum()); System.out.println("Subtraction="+obj.sub()); System.out.println("Multiplication="+obj.mul()); System. out.println("Division="+obj.div()); } } 6. Program with class variable that is available for all instances of a class. Use static variable declaration. Observe the changes that occur in the object's member variable values. class A6 static { int x; static int y,z; static void mul() { y = 5 ; z = 15; int m =y * z; System.out.println("Multiplication of y & z ="+m); } public static void main(String ar[]) { A6_static s1=new A6_static(); A6_static s2=new A6_static(); s1. x = 10 ; s2. x = 20 ; s1. y =100: s2. y = 200 ; System.out.println("sl's x ="+s1.x); System.out.println("s2's x ="+s2.x); System.out.println("s1's y="+ sl .y); System.out.println("s2's y="+s2.y); A6_static.mul(); } } 7. Program to create a student class with following attributes; Enrollment No: Name, Mark of subl, Mark of sub2, mark of sub3, Total Marks. Total of the three marks must be calculated only when the student passes in all three subjects. The passing mark for each subject is 50. If a candidate fails in any one of the subjects his total mark must be declared as zero. Using this condition write a constructor for this class. Write separate functions for accepting and displaying student details. In the main method create an array of three student objects and display the details. import java.util.*; public class A7 student { static int eno; static String name; static float m1, m2,m3,tot; static void input() { Scanner sc=new Scanner(System.in); System.out.println("Enter student enrollment no:"); eno-sc.nextInt(); System.out.println("Enter student name:"); name=sc.next(); System.out.println("Enter subjectı marks:") ; m1=sc.nextFloat(); System.out.println("Enter subject2 marks:"); m2=sc.nextFloat(); System.out.println("Enter subject3 marks:"); m3=sc.nextFloat(); } A7_student(float x, float y,float z) { if(x>=50 && y>=50 && =50) { tot-x+y+z; } else { tot=0; } } void display() { System.out.println("enrollment no is:"+eno); System.out.println("Name is: "+name); System.out.println("Marks1="+m1); System.out.println("Marks2="+m2); System.out.println("Marks3="+m3); System.out.println("Total="+tot); } public static void main(String a[]) { A7_student[] obj=new A7_student[3]; for(int i=0;i<3;i++) { A7_student.input(); obj[i]=new A7_student(m1,m2,m3); obj[i].display(); } } } 8. Write a program to demonstrate multiple inheritance and use of implementing Interfaces import java.io.*; interface circle { float pi= 3.142f; float compute (float r); } class rect { float compute (float l, float b) { return (1*b); } } class area extends rect implements circle { public float compute (float r) { return (pi*r*r); } } class A8_multipleI { public static void main(String args[]) { area a=new area (); System.out.println ("Area of circle ="+a.compute (1f)); System.out.println("Area of reetangle=" + a.compute (5f, 10f)); } } 9. Illustrate creation of thread by a) Extending Thread class. import java.io.*; class A extends Thread { public void run () { System.out.println("thread A is running"); } } class A9_thread { public static void main(String args[]) { A obj = new A (); obj.start(); } } B) Implementing Runnable Interfaces import java.io.*; class A implements Runnable { public void run() { System.out.println ("thread A is running"); } } class A9_Rthread { public static void main(String args[]) { A obj = new A(); Thread t = new Thread (obj); t.start(); } } 10. Create a package "BCA" in your current working directory. a. Create a class student in the above package with the following attributes: Name, age, gender. Include appropriate constructor and a method for displaying the details. package BCA; public class A11_student { String name,gender; int age; public A11_student(String n,int a,String g) { name=n; age=a; gender-g; } public void display() { System.out.println("Name is: "+name); System.out.println("Age is: "+age); System.out.println("Gender is: "+gender); } } b. Import above package and access the member variables and function contained in a package. import BCA.*; class A11_pkg { public static void main(String ar[]) { A11_student obj=new All_student("ab",20,"f"); obj.display(); } } B1 class B1_array { public static void main(String args[]) { try { int a[]=new int[-2]; System.out.println("Exception not caught because array size is negative"); } catch(NegativeArraySizeException e) { System.out.println("Exception caught \n beacuse array size is initialisd to negative value"); } } } B2 import java.io.*; class B2_Exception { public static void main(String args[]) { int x=10,y=0,z=0; try { z=x/y; } catch(ArithmeticException e) { System.out.println("exception caught:division by zero"); } finally { System.out.println("I am always here"); } } } B3 import java.applet.*; import java.awt.*; public class B3_win extends Applet { public void paint(Graphics g) { g.drawString("Java",50,80); } } B4 import java.applet.*; import java.awt.*; public class shape extends Applet { public void paint(Graphics g) { g.setColor(Color.orange); g.drawLine(10,10,40,40); g.drawRect(50,50,50,100); g.fillRect(120,120,100,100); g.drawOval(220,220,80,50); g.fillOval(300,300,50,50); } } B5 import java.awt.*; import java.awt.event.*; public class B5_grid { Frame f; B5_grid() { f=new Frame("Grid with Button"); Button b1=new Button("1"); Button b2=new Button("2"); Button b3=new Button("3"); Button b4=new Button("4"); Button b5=new Button("5"); Button b6=new Button("6"); Button b7=new Button("7"); Button b8=new Button("8"); Button b9=new Button("9"); Button b10=new Button("10"); Button b11=new Button("11"); Button b12=new Button("12"); Button b13=new Button("13"); Button b14=new Button("14"); Button b15=new Button("15"); f.add(b1); f.add(b2); f.add(b3); f.add(b4); f.add(b5); f.add(b6); f.add(b7); f.add(b8); f.add(b9); f.add(b10); f.add(b11); f.add(b12); f.add(b13); f.add(b14); f.add(b15); f.setLayout(new GridLayout(4,2)); f.setVisible(true); f.setSize(400,500); } public static void main(String args[]) { new B5_grid(); } } B6 import java.awt.*; import java.awt.event.*; public class b6_Button1 implements ActionListener { TextField t=new TextField(); Button b1=new Button("father"); Button b2=new Button("mother"); b6_Button1() { Frame f=new Frame(); f.setSize(233,600); f.setVisible(true); f.setLayout(new GridLayout(3,1)); b1.addActionListener(this); b2.addActionListener(this); f.add(b1); f.add(b2); f.add(t); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { t.setText("father name is:ABC father age is:56 father designation=farmer"); } else if(e.getSource()==b2) { t.setText("mother name is:XYZ mother age is:47 mother designation=mother"); } } public static void main(String ar[]) { new b6_Button1(); } } B7 import java.awt.*; import java.awt.event.*; public class B7 implements ActionListener { Frame f; Button b; TextField t; B7() { f=new Frame(); b=new Button("Click"); t=new TextField(); f.setSize(300,500); f.setVisible(true); f.setLayout(new GridLayout(2,1)); f.add(t); f.add(b); b.addActionListener(this); } public void actionPerformed(ActionEvent e) { t.setText("Name:Abhi Degree:BCA"); } public static void main(String args[]) { new B7(); } } B8 import java.awt.*; import java.applet.*; import java.awt.event.*; public class B8 extends Applet implements ActionListener { TextField t1,t2,t3; Label l1,l2,l3; Button b1,b2; public void init() { t1=new TextField(20); t2=new TextField(20); t3=new TextField(20); l1=new Label("A"); l2=new Label("B"); l3=new Label("A+B"); b1=new Button("Add"); b2=new Button("Clear"); add(l1); add(t1); add(l2); add(t2); add(l3); add(t3); add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e) { int a,b,sum; if(e.getSource()==b1) { a=Integer.parseInt(t1.getText()); b=Integer.parseInt(t2.getText()); sum=a+b; t3.setText(Integer.toString(sum)); } else if(e.getSource()==b2) { t1.setText(" "); t2.setText(" "); t3.setText(" "); } } } B9import java.awt.*; import java.awt.event.*; public class B9_key extends Frame implements KeyListener { TextField t; public B9_key() { Frame f=new Frame("Key board Events"); t=new TextField(); f.add(t); f.setSize(400,400); f.setVisible(true); t.addKeyListener(this); } public void keyTyped(KeyEvent ke) { if(ke.getKeyChar()=='M'||ke.getKeyChar()=='m') { t.setText("Good Morning"); } else if(ke.getKeyChar()=='A'||ke.getKeyChar()=='a') { t.setText("Good Afternoon"); } else if(ke.getKeyChar()=='E'||ke.getKeyChar()=='e') { t.setText("Good Evening"); } else if(ke.getKeyChar()=='N'||ke.getKeyChar()=='n') { t.setText("Good Night"); } else { t.setText(" "); } } public static void main(String args[]) { new B9_key(); } } B10 import java .awt.*; import java .awt.event.*; public class mouse extends Frame { public mouse() { me obj =new me(); addMouseListener(obj); addMouseMotionListener(obj); setSize(400,300); setVisible(true); } public static void main(String ar[]) { new mouse(); } } class me extends MouseAdapter { public void mouseTyped(MouseEvent e) { System.out.println("mouse typed"); } public void mouseReleased(MouseEvent e) { System.out.println("mouse released"); } public void mousePressede(MouseEvent e) { System.out.println("mouse pressed"); } public void mouseExited(MouseEvent e) { System.out.println("mouse exited"); } public void mouseClicked(MouseEvent e) { System.out.println("mouse Clicked at:"+e.getX()+","+e.getY()); } public void mouseMoved(MouseEvent e) { System.out.println("mouse moved at:"+e.getX()+","+e.getY()); } public void mouseDragged(MouseEvent e) { System.out.println("mouse Dragged at:"+e.getX()+","+e.getY()); } } B11 import java.awt.*; public class Menu_demo { public Menu_demo() { Frame f=new Frame("Menu Ex"); MenuBar mb=new MenuBar(); Menu m=new Menu("Degree"); Menu sb=new Menu("Science"); MenuItem i1=new MenuItem("BCA"); MenuItem i2=new MenuItem("BBA"); MenuItem i3=new MenuItem("BCOM"); MenuItem i4=new MenuItem("BSC"); MenuItem i5=new MenuItem("MSC"); sb.add(i4); sb.add(i5); m.add(i1); m.add(i2); m.add(i3); m.add(sb); mb.add(m); f.setMenuBar(mb); f.setSize(400,400); f.setVisible(true); } public static void main(String args[]) { new Menu_demo(); } }