Practical No.

: 1
Write a Java program to sort the numbers given by an array Code: public class Sort { public static void main(String ar[]) { int numbers[]= new int[5]; int k=0; System.out.print("Given List:"); for(int i=0; i<5; i++) { numbers[i]=Integer.parseInt(ar[k]); k++; System.out.print(" "+numbers[i]); } System.out.println("\n"); for(int i=0; i<5; i++) { for(int j=i+1; j<5; j++) { if(numbers[i]<numbers[j]) { int temp=numbers[i]; numbers[i]=numbers[j]; numbers[j]=temp; } } } System.out.print("Sorted List:"); for(int i=0; i<5; i++) { System.out.print(" "+numbers[i]); } System.out.println(" "); } } Output: C:\Java\jdk1.6.0_12\bin>java Sort 12 78 26 99 5 Given List: 12 78 26 99 5 Sorted List: 99 78 26 12 5

Practical No.:2
Write a Java program to find mean and standard deviation of an array of numbers. Code: class Mean { public static void main(String ar[]) { int numbers[]= new int[5]; int k=0; System.out.print("Given List:"); for(int i=0; i<5; i++) { numbers[i]=Integer.parseInt(ar[k]); k++; System.out.print(" "+numbers[i]); } System.out.println("\n"); double mean, sum=0; for(int i=0;i<5;i++) { sum=sum+numbers[i]; } mean=sum/5; System.out.println("Mean of given numbers is: "+mean); double dev,avg=0; for (int i = 0; i < 5; i++) { avg += Math.pow((numbers[i] - mean),2); } dev = Math.sqrt(avg / (5)); System.out.println("Standard deviation of given numbers is: "+dev); } }

Output: C:\Java\jdk1.6.0_12\bin>java Mean 11 12 33 54 75 Given List: 11 12 33 54 75 Mean of given numbers is: 37.0 Standard deviation of given numbers is: 24.698178070456937

Practical No.:3
Write a Java program to display 3 x 3 matrix. Code: class Matrix { public static void main(String[] args) { int i,j,k; int a[][]=new int[3][3]; k=0; for(i=0;i<3;i++) { for(j=0;j<3;j++) { a[i][j]=Integer.parseInt(args [k]); k++; } } System.out.println("Matrix Elements are:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { System.out.print(a[i][j]+" "); } System.out.println(" "); } } }

Output: C:\Java\jdk1.6.0_12\bin>java Matrix 12 45 85 69 45 21 36 25 45 Matrix Elements are: 12 45 85 69 45 21 36 25 45

i<2. } } for(i=0. Code: class MatSum { public static void main(String ar[]) { int i.k=0. int b[][]=new int[2][3].Practical No.j. } } System.i++) { for(j=0. for(i=0.parseInt(ar[k]).: 4 To initialize 2 two dimensional array of order 2X3 and to find their sum. k++.i<2. The program should display the three arrays.j++) { c[i][j]=a[i][j]+b[i][j]. k++.parseInt(ar[k]).j<3. } .out.i++) { for(j=0. int a[][]=new int[2][3]. } } for(i=0.i<2.println("First Matrix").j<3.j++) { b[i][j]=Integer. int c[][]=new int[2][3].j<3. for(i=0.out.i<2.i++) { for(j=0.j++) { System.i++) { for(j=0.j<3.j++) { a[i][j]=Integer.print(a[i][j]+" ").

out. for(i=0.j++) { System.j<3. } System.println(" ").println(" ").println("Second Matrix").println("Resultant Matrix"). } System.i<2. } } } Output: C:\Java\jdk1.out.System.j<3.i<2.out.0_12\bin>java MatSum 1 2 3 4 5 6 7 8 9 10 11 12 First Matrix 1 2 3 4 5 6 Second Matrix 7 8 9 10 11 12 Resultant Matrix 8 10 12 14 16 18 . } System.out.j++) { System.out.6.println(" ").print(c[i][j]+" ").out.i++) { for(j=0.out.print(b[i][j]+" "). } System. for(i=0.i++) { for(j=0.

i<2. int c[][]=new int[2][2].i<2.j<2. int b[][]=new int[2][2].j<2. for(i=0.j<2.parseInt(args [k]).Practical No.i++) { for(j=0. } } for(i=0.k++) { c[i][j]+=a[i][k]*b[k][j].k. int a[][]=new int[2][2].j++) { c[i][j]=0. } } for(i=0. Code: class Multiply { public static void main(String[] args) { int i.j.i++) { for(j=0.i<2.i++) { for(j=0.parseInt(args [k]).i++) { for(j=0. } } for(i=0. k++.j++) { for(k=0.j++) { a[i][j]=Integer.j<2. The program should display the three arrays. k=0.i<2.j++) { b[i][j]=Integer.k<2. k++.: 5 To initialize 2 two dimensional array of order 2X2 and to find their product. .

for(i=0.out.6.print(c[i][j]+" ").out. } System.print(a[i][j]+" ").println("First matrix is:").out.println(" ").i<2.out.out.j<2.i++) { for(j=0. for(i=0.out.println(" "). } System. } System.out.i++) { for(j=0.i++) { for(j=0. } } } Output: C:\Java\jdk1.println(" ").out.0_12\bin>java Multiply 2 12 22 54 14 18 87 69 First matrix is: 2 12 22 54 Second matrix is: 14 18 87 69 Multiplied matrix is: 1072 864 5006 4122 .j++) { System.i<2. } System.println("Multiplied matrix is:").} } } System.j<2.out.print(b[i][j]+" ").j<2. } System.j++) { System.println("Second matrix is:"). for(i=0.j++) { System.i<2.

Code: class Transpose { public static void main(String args[]) { int i.i++) { for(j=0.j++) { a[i][j]=Integer. k=0.out.j<3.out.i++) { System. } } } .println(" ").print(a[i][j]+" ").i<4.j++) { for(i=0. } System.: 6 To initialize a two dimensional array of order 4X3 and to find its transpose. } System. int a[][]=new int[4][3]. The program should display both the arrays. k++. } System.println("The given matrix is:"). for(i=0.out.parseInt(args [k]).println(" ").println("Transpose of given matrix is:"). } } System.out.print(a[i][j]+" ").j<3. for(j=0.j.i<4.j<3.i<4.j++) { System.Practical No.k.i++) { for(j=0.out. for(i=0.out.

0_12\bin>java Transpose 11 21 33 54 45 76 79 48 19 10 25 78 The given matrix is: 11 21 33 54 45 76 79 48 19 10 25 78 Transpose of given matrix is: 11 54 79 10 21 45 48 25 33 76 19 78 .6.Output: C:\Java\jdk1.

disp().i++) { if(a%i==0) System.Practical No.parseInt(args[0]).6. for(int i=1. A (int num) { a=num.:7 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will display all divisors of y.println("Divisors of "+a+" are: "). } } Output: C:\Java\jdk1.i<=y.println(i+" "). Class B contains the main() and calls the method for a value of your choice. num=Integer.out. System.out.0_12\bin>java B 4587 Enter a number Divisors of 4587 are: 1 3 11 33 139 417 1529 4587 . y. } } } class B { public static void main(String args[]) { int num. A y=new A(num). Code: class A { int a. } void disp() { System.println("Enter a number").out.

: 8 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will check whether y is a perfect number or not.println("Enter a number:").Practical No. System.out.i++) { if(a%i==0) { b=b+i. } void perfect() { int b=0.i<=a-1.perfect(). Code: class A { public int a.parseInt(ar[0]). } } . num=Integer. A y=new A(num).out.println(a+" is not a perfect number"). } } if(a==b) { System.println(a+" is a perfect number"). y. Class B contains the main() and calls the method for a value of your choice. public A(int num) { a=num. } } class B { public static void main(String ar[]) { int num.out. } else System. for(int i=1.

0_12\bin>java B 496 Enter a number: 496 is a perfect number C:\Java\jdk1.6.Output: C:\Java\jdk1.0_12\bin>java B 494 Enter a number: 494 is not a perfect number .6.

z=Integer. The class defines a constructor to initialize these variables and a method that finds whether the quadratic equation for an instance of the class has real roots or complex roots. y=Integer. public Quad(int x.out. Create a class Quadratic containing the main() method.check().println("Enter co-efficients:"). b=y.Practical No. Make an instance (object) of the above class to find the nature of the roots and display proper messages. q1. denoting the coefficient of a quadratic equation.parseInt(ar[0]). b and c as variables. System.out. } void check() { double eq=(b*b)-(4*a*c).y. Code: class Quad { private int a.int z) { a=x. } } .z).y.parseInt(ar[1]).println("Both roots are Complex"). if(eq>0) System.println("Both roots are real").c. x=Integer.out. } } class Quadratic { public static void main(String ar[]) { int x.z.parseInt(ar[2]). Quad q1=new Quad(x. c=z. if(eq<0) System.: 9 Create a class called Quad containing a.b.int y.

0_12\bin>java Quadratic 2 1 1 Enter co-efficients: Both roots are Complex C:\Java\jdk1.Output: C:\Java\jdk1.6.6.0_12\bin>java Quadratic 1 3 1 Enter co-efficients: Both roots are real .

System. } } Output C:\Java\jdk1. num=Integer.out.Practical No.println(y+" is not a leap year"). Class B contains the main() and calls the above method and displays whether y is a leap year or not a leap year.:10 Create a class called A containing the instance variable y which denotes a year and defines a constructor to initialize the instance variable and a method that will check whether it is a leap year or not.println("Enter a year"). A a=new A(num).6.out.0_12\bin>java B 2011 Enter a year 2011 is not a leap year C:\Java\jdk1.out.0_12\bin>java B 2005 Enter a year 2005 is not a leap year . a. Code class A { public int y. } void leap() { if((y%4==0)&&(y%100!=0)||(y%400==0)) System. else System.parseInt(ar[0]).println(y+" is a leap year"). public A(int num) { y=num. } } class B { public static void main(String ar[]) { int num.leap().6.

Code: class A { public int a.println(a+" is divisible by 5").0_12\bin>java B3 1000 Enter a number 1000 is divisible by 5 C:\Java\jdk1.6. } } Output: C:\Java\jdk1.:11 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will check whether it is divisible by 5.println("Enter a number").parseInt(ar[0]).6. else System.out. num=Integer. Class B contains the main() and calls the method for a value of your choice and displays whether y is divisible by 5 or not. System.Practical No. public A(int num) { a=num.out.0_12\bin>java B3 1001 Enter a number 1001 is not divisible by 5 . A y=new A(num). y.println(a+" is not divisible by 5").out. } } class B3 { public static void main(String ar[]) { int num.divisible(). } void divisible() { if(a%5==0) System.

y. System. System.out.0 .println("Factorial of "+num+" is:").j<=num.out. public A(int num) { a=num.Practical No.println("Enter a number").out.0_12\bin>java B4 10 Enter a number Factorial of 10 is: 3628800. num=Integer. Code: class A { public int a.j++) fact =fact*j. } void factorial(int num) { double fact=1.parseInt(ar[0]). System.factorial(num). } } class B4 { public static void main(String ar[]) { int num. Class B contains the main() and calls the method for a value of your choice and displays the factorial. } } Output: C:\Java\jdk1. A y=new A(num). for(int j=1.6.:12 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will find the factorial of a number.0.println(fact).

println("ERROR"). else if((a%6==0)&&((a%4==0)!=(a%6==0))) System. public A(int num) { a=num.println(a+" is divisible by 4").:13 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will check whether it is divisible by 4 or 6 but not both.divisible(). System.parseInt(ar[0]).0_12\bin>java B5 24 Enter a number ERROR C:\Java\jdk1. y.out.0_12\bin>java B5 18 Enter a number 18 is divisible by 6 .6.println(a+" is divisible by 6"). A y=new A(num). Class B contains the main() and calls the method for a value of your choice and displays the proper message. } } class B5 { public static void main(String ar[]) { int num. } void divisible() { if((a%4==0)&&((a%4==0)!=(a%6==0))) System. if((a%4==0)==(a%6==0)) System. } } Output: C:\Java\jdk1.println("Enter a number").out.6.6. Code: class A { public int a.out.Practical No. num=Integer.out.0_12\bin>java B5 8 Enter a number 8 is divisible by 4 C:\Java\jdk1.

} } class B6 { public static void main(String ar[]) { int num.parseInt(ar[0]).Practical No.out.println("Numbers from 1 to "+num+" divisible by 5 are:"). System. num=Integer. for(int i=1.println("Enter a number"). public A(int num) { a=num. y.out.i++) if(i%5==0) System. } } Output: C:\Java\jdk1.0_12\bin>java B6 30 Enter a number Numbers from 1 to 30 divisible by 5 are: 5 10 15 20 25 30 . } void divisible(int num) { System.out. Code: class A { public int a.:14 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will display all numbers between 1 and y that are divisible by 5.i<=num.divisible(num). A y=new A(num).6.println(i). Class B contains the main() and calls the method for a value of your choice.

parseInt(ar[0]).i++) if((i%6==0)||(i%8==0)) System.out. Class B contains the main() and calls the method for a value of your choice.0_12\bin>java B7 30 Enter a number Numbers from 1 to 30 divisible by 6 or 8 are: 6 8 12 16 18 24 30 .} void divisible(int num) { System. System.println(i). } } Output: C:\Java\jdk1. } } class B7 { public static void main(String ar[]) { int num. y.out. public A(int num) { a=num.6.i<=num.divisible(num). Code: class A { public int a.println("Enter a number").out.:15 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will display all numbers between 1 and y that are divisible by 6 or 8.Practical No. A y=new A(num). num=Integer. for(int i=1.println("Numbers from 1 to "+num+" divisible by 6 or 8 are:").

out. System.i<=num.i++) if(((i%6==0)||(i%8==0))&&((i%6==0)!=(i%8==0))) { System.out. for(int i=1.Practical No.println("Enter a number"). num=Integer.6. public A(int num) { a=num. } } } class B8 { public static void main(String ar[]) { int num. A y=new A(num).divisible(num).println(i). } } Output: C:\Java\jdk1. Class B contains the main() and calls the method for a value of your choice.println("Numbers from 1 to "+num+" divisible by 6 or 8 are:"). y.parseInt(ar[0]).:16 Create a class called A containing the instance variable y (integer) and defines a constructor to initialize the instance variable and a method in this class that will display all numbers between 1 and y that are divisible by 6 or 8 not both. Code: class A { public int a. } void divisible(int num) { System.0_12\bin>java B8 30 Enter a number Numbers from 1 to 30 divisible by 6 or 8 are: 6 8 12 16 18 30 .out.

println("The sum is: "+sum). } System.0_12\bin>java B9 5 Enter a value for n The sum is: 1. } void calc() { int n.:17 Create a class called A containing instance variable n and defines a constructor to initialize the instance variable and a method in this class that will find the following sum 1 + 1 / 2 + 1 / 4 + 1 / 8 + .parseInt(ar[0]). y. .println("\n"). A y=new A(n).Practical No.pow(2.calc(). . } } Output: C:\Java\jdk1.i<a. double sum=0.9375 .println("Enter a value for n"). } } class B9 { public static void main(String ar[]) { int n. for(int i=0.i++) { sum = sum + 1/Math. A (int n) { a=n. Class B contains the main() and calls the method and displays the sum. .6. Code: class A { int a. 1 / 2n.out. System. System.out.out.i). n=Integer.

sint(2500.println("Enter the number of years:").out. } } Output: C:\Java\jdk1.sint(2500.int y) { p=x. Class Action creates two instances (objects) of the above class one to find the simple interest and the other to find the compound interest containing main() and display the respective interests using your own data values.5). i++. double p. this method to be overloaded to find the compound interest for an amount invested for n number of years.println("The simple interest for a year = "+si). System.int z){ int i=1.5.0_12\bin>java ActionInterest 6 Enter the number of years: The simple interest for a year = 125.parseInt(args[0]). System. r=y. void sint(int x. while(i<=z){ ci=(p*r)/100. int z=Integer.out. si. } System.z).Practical No. p=x. p=ci. } } class ActionInterest { public static void main(String args[]) { Interest si=new Interest().0 The compound interest for 6 years = 3. Code: class Interest { double si=0. Interest ci=new Interest(). ci. r=y. si=(p*r)/100.int y.out. they being the principal and rate of interest respectively and the class defines a method to find the simple interest for a year. } void sint(int x.println("The compound interest for "+z+" years = "+ci).:18 Create a class called Interest with variables p and r.ci=0.r.90625E-5 .6.

print("Area of square is: ").println(area2).30).out. } void area(int c . Area A2=new Area().b.:19 Create a class called Area with variable l and b.int d) { l=c. System.println(area1).area(20.6.print("Area of rectangle is: "). int area2= l*b. A2. Class Action creates two instances (objects) of the above class one to find the area of a square and the other to find the area of a rectangle containing main() and display the respective area using your own data values. System. they being the breadth and height of a quadrilateral and the class defines a method A to find the area of a square.0_12\bin>java ActionArea Area of square is: 100 Area of rectangle is: 600 . } } Output: C:\Java\jdk1. } } class ActionArea { public static void main(String ar[]) { Area A1=new Area(). Code: class Area { int l.print("\n").out. b=d. System. int area1= l*l. System.area(10). A1. this method to be overloaded to find the area of a rectangle.out.out.out. void area(int a) { l=a. System.Practical No.

marks[0] = d. String b. String c ) { rollno = a.0. cls = c. marks[0] = 15. name and class as parameters and fix the corresponding instance variables. } Student(int a. Class also contains a method called show() to display the values of all instance variables. average = 0. Each object should use different constructor. } Student(int a.:21 Write a Java program to write the following classes: Class Student contains instance variables roll number.Bsc. cls ="F. marks[1] = 0. Now. int e { rollno = a. marks[0] = 0. create a class containing main() method to create 3 different objects of Student class. marks2=0. ) . Student () { rollno = 1. marks[1] = e. double[] marks = new double[2]. cls = c. marks obtained in two papers of a subject and average.Y. marks1=0.´. double average. String name. name = b.int d. String cls. Invoke show() for all three objects. marks[1] = 20. Code: class Student { int rollno.(iii) Define third constructor to accept all parameters except average which should be calculated on the basis of marks1 and marks2. name = "Virender".Y. class.Practical No. String c . String b. This class contains following constructors: (i) Default constructor to initialize class with ³F.0 (ii) Define another constructor to accept roll number.Bsc". name. name = b.0. average = (marks[0]+marks[1])/2.

23.20).Bsc Marks -. System.Y. } void show () { System.Y."Rahul".0 Paper 2 : 0."Sachin".0 Average of Paper 1 & 2 : 21.out.0 Average of Paper 1 & 2 : 0.average = (marks[0]+marks[1])/2.Y. ob3.out.show().Paper 1 : 0."F. Student ob3 = new Student(3.println("Roll no: "+rollno+"\tName: "+name+"\tClass: "+cls). } } Output: C:\Java\jdk1."F.0 Paper 2 : 20.Bsc").0_12\bin>java StudentDemo The student details are: Roll no: 1 Name: Virender Class: F. Student ob2 = new Student(2. System.5 . System.Paper 1 : "+marks[0]+"\tPaper 2 : "+marks[1]).out.out. ob2.Paper 1 : 23.Bsc".print("\n").0 Average of Paper 1 & 2 : 17.println("Average of Paper 1 & 2 : "+average).println("The student details are:").5 The student details are: Roll no: 3 Name: Rahul Class: F.0 Paper 2 : 20.out. } } class StudentDemo { public static void main(String args[]) { Student ob1 = new Student(). ob1.show().Bsc Marks -. System.6.show().Bsc Marks -.Y.Y.0 The student details are: Roll no: 2 Name: Sachin Class: F.println("Marks -.Paper 1 : 15.

:22 Develop the following classes: A Cube class contains length as instance variable with constructor. . } void volume () { int vol = length*height*breadth.out. A Cuboid class contains height and breadth and inherits length from Cube class. breadth = c. System.print("\n"). The display() method inherits display() of class Cube and height and breadth of Cuboid class. } } class Cuboid extends Cube { int height. Code: class Cube { int length . A Cube_Cuboid class defines an object of Cuboid class and displays surface and area.out. A surface() method calculates the surface of cube.out. height = b. breadth.print("\n").println("The surface area of the Cube is :" +surf). System.println("The volume of cuboid is : " +vol).out. Cube (int a) { length = a. volume() method calculate volume of a cuboid. } void display () { System.out.Practical No. System. display() method displays the length of a cube. } void surface () { int surf = 6*length*length. Cuboid (int a .println("The length of the Cube is : " +length).print("\n"). System. int c) { super(a). int b. System.out.

out.} void display () { super. System.println("The height and breadth of cuboid is : "+height+" & " +breadth).volume().6).display().surface(). Cube_cuboid.print("\n"). System. Cube_cuboid.out.3. } } class Cube_cuboid { public static void main(String args[]) { Cuboid Cube_cuboid = new Cuboid(2.display(). Cube_cuboid.0_12\bin>java Cube_cuboid The length of the Cube is : 2 The height and breadth of cuboid is : 3 & 6 The surface area of the Cube is :24 The volume of cuboid is : 36 .6. } } Output: C:\Java\jdk1.

out. else System. this class contains a method that will instantiate the two instance variables and a method which display the message ³I love apples´ if n10 and display ³I love mangoes´ otherwise.println("I love mangoes"). int b) { super(a). Code: class Disp { int n.println("I love apples"). } } . This class is inherited by another class Display containing the instance variable n. Display(int a. } } class Display extends Disp { int n.out. this.println("I am great").println("I am good").Practical No. to display the following messages ³I am good´ whenever n < 0 and the message ³I am great´ otherwise. Create a class containing the main() and display the messages according to the value you have given to the two variables. } void display () { disp(). if (n!=10) System.out. } void disp () { if (n<0) System. Disp(int a) { n = a.:23 Create a class called Disp containing the instance variable n.n = b.out. else System.

Display obj = new Display(a.0_12\bin>java Main 5 -10 Enter the number I am great I love apples C:\Java\jdk1.b). int b=Integer.6.0_12\bin>java Main -5 10 Enter the number I am good I love mangoes C:\Java\jdk1.parseInt(args[1]).class Main { public static void main(String args[]) { System.0_12\bin>java Main -5 -10 Enter the number I am good I love apples . } } Output: C:\Java\jdk1.println("Enter the number").out.0_12\bin>java Main 5 10 Enter the number I am great I love mangoes C:\Java\jdk1. obj.6.display().parseInt(args[0]).6. int a=Integer.6.

50). public class Name extends Applet { String str1.6.0_12\bin>javac Name. public void init() { str1=getParameter("name").Practical No.*.java C:\Java\jdk1. } public void paint(Graphics g) { g.class width=500 height=200> <PARAM NAME="name" value="ANEESH NAIR"> </Applet> Output: C:\Java\jdk1.applet.drawString(str1.*.html .6.*.:25 Write Java applet to insert the name of a person using HTML tag and display it with applet viewer in front of the message ³What is your name?´ Code: import java. } } HTML Code: <Applet code=Name.awt.awt.0_12\bin>appletviewer Name.event. str1="What is your name? "+str1. import java.10. import java.

drawOval(85.Practical No.30.20).81.drawOval(40.applet. public class Face extends Applet { public void paint(Graphics g) { g.120. g.:26 Write an applet to display a face of a person. g.6. import java.150).10.180. g.10.drawArc(60. g. g.100.0_12\bin>appletviewer Face.92.30.drawOval(160.class width=500 height=300> </Applet> Output: C:\Java\jdk1.30.*.80. Code: import java.75.30).125.30).10). g.15.html .20).92.40.15.75. g.awt.40.drawOval(57.java C:\Java\jdk1. g.81.180).fillOval(68. } } HTML Code: <Applet code=Face.6.0_12\bin>javac Face.*.fillOval(121.drawOval(110.drawOval(25.30).10).

50).:27 Write Java applet to insert the users name and pass word of a person using HTML tag and display it with applet viewer in front of the messages ³User ID´. str2=getParameter("password"). str2="Password: "+str2.0_12\bin>javac UsePass. ³Password´ should be displayed Code: import java.*.0_12\bin>appletviewer UsePass.event. .*. str1="User Name: "+str1.class width=500 height=300> <PARAM NAME="user" value="Aneesh"> <PARAM NAME="password" value="arc140194"> </Applet> Output: C:\Java\jdk1. import java.10.drawString(str2.drawString(str1.6. public void init() { str1=getParameter("user"). } } HTML Code: <Applet code=UsePass.6.10.*. import java. public class UsePass extends Applet { String str1.str2.html The image part w ith relationship ID rId7 w as not found in the file.Practical No.awt.applet.java C:\Java\jdk1. g.100). } public void paint(Graphics g) { g.awt.

:28 Write a program to accept the elements of the classes 1. t2=new TextField(8). t1. t3. t3=new TextField(8). The salary slips along with calculation of D.A and Gross Salary should be printed on the applet. t2. C.getText().A.0.C.t3. public void init() { t1=new TextField(8). public class Salary extends Applet { TextField t1. s3=t3.A.drawString("Input Empno. try { s1=t1..getText().Practical No. These elements are passed through the applet using text field.getText().C. Emp_no (ii) basic_pay (iii) Dept.cca. H.C. s2=t2.gs=0.setText("0").setText("0").*. add(t3).A.A = 350/H. g. The D.awt. import java. . Dept. = 15% of basic salary if basic salary < 5000 if basic salary is in the range 5000 to 7000 if basic salary > 7000 Code: import java.R. } public void paint(Graphics g) { int bp=0.hra=0.10.A and C.setText("0"). add(t2).50).t2. add(t1).. double d=0. String s1.s3.0. Salary in the boxes given".0. = 81% of basic salary = 51% of basic salary = 41% of basic salary C.applet.c.R.*.A are calculated as D.A.s2.

} else { if(bp>5000 && bp<=7000) { d=(0. hra=0.10.75). } catch(Exception e){ } if(bp<=5000) { d=(0.41)*bp.valueOf(gs). . c=String.drawString("The gross salary is : "+c. } else { d=(0. } } HTML Code: <Applet code=Salary.class width=800 height=500> </Applet> Output: C:\javaprog>javac Salary. gs=bp+d+hra+cca.51)*bp.html The image part w ith relationship ID rId8 w as not found in the file.java C:\javaprog>appletviewer Salary.15*bp. g. } } cca=350.parseInt(s3).bp=Integer.81)*bp.