You are on page 1of 97

2630006 – Programming Skills IV (Java

)
1. Observe the interactions involved in the process of booking a railway ticket.
Identify the various objects involved and the interactions between the objects in
order to solve a problem of booking a railway ticket.

{

import java.io.*;
class Ticket
public static void main(String S[]) throws IOException
{

BufferedReader
br
=
new
BufferedReader(new
InputStreamReader(System.in));
Train T[] = new Train[5];
T[0] = new Train("RAJDHANI
",100,200,300);
T[1] = new Train("SHATABDI
",130,200,120);
T[2] = new Train("KARNAVATI
",150,200,250);
T[3] = new Train("INTERCITY
",120,160,200);
T[4] = new Train("METRO EXPRESS ",100,100,100);
int x;
do
{
System.out.print("\n-------------------------------");
System.out.print("\n Main Menu ");
System.out.print("\n-------------------------------");
for(int i=0;i<5;i++)
{
System.out.print("\n"+(i+1) +" "+T[i].Train_Name + "
"+ T[i].TotalSeat());
}
System.out.print("\n0 EXIT ");
System.out.print("\n-------------------------------");
System.out.print("\n ENTER TRAIN NO : ");
x = Integer.parseInt(br.readLine());
if(x <= 5 && x > 0)
{
T[x-1].menu();
}
}
while(x!=0);
}
}
class Train
{
public
BufferedReader
br
=
new
BufferedReader(new
InputStreamReader(System.in));
public String Train_Name;
privateint c1,c2,c3;
public Train()
{
c1 = 0;
c2 = 0;
c3 = 0;
}
public Train(String Tnm,int First,int Second,int Third)
{
Train_Name = Tnm;
c1 = First;
c2 = Second;
c3 = Third;

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar

1

2630006 – Programming Skills IV (Java)
}
public void class1()
{
c1--;
}
public void class2()
{
c2--;
}
public void class3()
{
c3--;
}
public int TotalSeat()
{
return (c1+c2+c3);
}
public void AvailableSeats()
{
System.out.print("\n-------------------------------");
System.out.print("\nTOTAL SEAT OF " + Train_Name );
System.out.print("\n-------------------------------");
System.out.print("\n FIRST CLASS :" + c1);
System.out.print("\n SECOND CLASS :" + c2);
System.out.print("\n GENERAL CLASS :" + c3);
System.out.print("\n-------------------------------");
System.out.print("\n TOTAL SEATS :" + TotalSeat());
System.out.print("\n-------------------------------");
}
public void GetSeatno() throws IOException
{
System.out.print("\n-------------------------------");
System.out.print("\n1 FOR FIRST CLASS");
System.out.print("\n2 FOR SECOND CLASS");
System.out.print("\n3 FOR GENERAL CLASS");
System.out.print("\n-------------------------------");
System.out.print("\nENTER YOU’RE CHOICE : ");
int ch = Integer.parseInt(br.readLine());
System.out.print("\n-------------------------------");
switch(ch)
{
case 1:this.class1(); break;
case 2:this.class2(); break;
case 3:this.class3(); break;
default: System.out.print("\nINVALID CHOICE CODE"); break;
}
}
void menu() throws IOException
{
System.out.print("\n-------------------------------");
System.out.print("\n 1 AVAILABLE SEATS IN TRAIN");
System.out.print("\n 2 GETSEAT NO");
System.out.print("\n 3 EXIT");
System.out.print("\n-------------------------------");
System.out.print ("\n ENTER YOUR CHOICE : ");
int x = Integer.parseInt(br.readLine());
System.out.print ("\n-------------------------------");
switch (x)
{

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar

2

2630006 – Programming Skills IV (Java)

}

Break;
}

case 1:
case 2:
case 3:
default:

Available Seats();
break;
GetSeatno();
break;
break;
System.out.print("\nINVALID CHOICE CODE");

}
2.

Write a simple java application to print a pyramid with 5 lines. The first line has
one character, 2nd line has two characters and so on. The character to be used in
the pyramid is taken as a command line argument.
class Asspra2
{
public static void main(String s[])
{

}

if(s.length <= 0)
System.out.print("Pass Arguments Properly...!");
else
{
char c = s[1].charAt(0);
for(int i=0;i<=Integer.parseInt(s[0]);i++)
{
for(int j=0;j<i;j++)
{
System.out.print(c);
}
System.out.print("\n");
}
}

}

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar

3

println( (i+1) + ":" +a[i+1]+" Student Name is : " +s[i]). a = new String[20].out. a[6] = "Sixth". a[9] = "Nineth".i++) System.: Third Student Name is = Harry class Asspra3 { public static void main(String s[]) { String a[].: Second Student Name is = Dick 3.Write a class. } } 4. a[4] = "Forth". a[3] = "Third". System. Number of arguments = 3 1. a[5] = "Fifth".println("Number of arguments = " +s. a[8] = "Eighth". a[10] = "Tenth". which are supposed to be names of students and prints output as given below: (Suppose we enter 3 names then output should be as follows). Write a Java application which takes several command line arguments.2630006 – Programming Skills IV (Java) 3.out. a[7] = "Seventh". for(int i=0.. a[2] = "Second". also observe the effect Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 4 . which declares floating point variables and observe the output of dividing the floating point values by a 0. a[1] = "First".: First Student Name is = Tom 2.i<s.length). with main method.length.

which creates a two-dimensional array for the four weeks of a month. sum += x. which takes a one-dimensional array for double type. import java. as parameter. y = (int) x.Write a class called Statistics.1010f. a[0][6] = 22. Now write a class with the main method. } } class Asspro5 { public static void main(String args[]) { double[][] a = new double[4][7].33. int y = 1234567890.35. class Statistics { public static double average(double temp[]) { int i=0. a[0][3] = 40. a[0][5] = 34. and prints the average for the values in the array.println(x/0).23.34. containing minimum temperatures for the days of the week(an array of 4 by 7). System. System.34.util. } return sum/i. } } 5.println(y). for(double x:temp) { i++. class Asspra4 { public static void main(String s[]) { float x = 10.2630006 – Programming Skills IV (Java) of assigning a high integer value (8 digits and above) to a float and casting it back to int and printing.out. double sum=0. a[0][4] = 45.12.56. a[0][1] = 30.out. and uses the average method of the Statistics class to compute and print the average temperatues for the four weeks.println(y). System. which has a static method called average.out. a[0][0] = 25. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 5 . a[0][2] = 35.*.

printf("\nEnter Product Code :").25. } public Product(int code.average(a[3])). methods and constructors. a[3][1] = 45. BufferedReader br = new BufferedReader(new InputStreamReader(System. a[3][6] = 45.io.55.average(a[0])).*.String manufacture) { P_code = code.*. a[3][4] = 12.33. a[3][0] = 49. a[3][5] = 24.out. P_name = name. a[3][3] = 33. } public void setpdetail() throws IOException { System.2630006 – Programming Skills IV (Java) System.printf("Average %3.2f". P_manufacture = manufacture.56.out.00.Statistics.2f".Statistics. a[3][2] = 48. P_name = "".String name. for the Product class. System. private String P_manufacture. Write a class called TestProduct. public Product() { P_code = 0.20.util. class Product { private int P_code. } } of of 1st 3rd Week : Week : 6.20. define variables.out.printf("\nAverage %3. Define a class called Product. private String P_name. each product has a name. P_manufacture = "". import java. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 6 . import java.in)). a product code and manufacturer name. with the main method to test the methods and constructors of the Product class.

Now define a class called TestCartesianPoint. } } 7.getpdetail().out. a method called display() which would display the current values of x and y.readLine().P_name).P_manufacture).out. .2630006 – Programming Skills IV (Java) P_code = Integer. System. System. System. P_manufacture = br."monitor"."LG"). Product p3 = new Product(). Now overload the method move() to work with single parameter.setpdetail().out.printf("\n======================================="). with the main method to test the various methods in the CartesianPoint class.getpdetail(). System. p1. a method called move() which would take two integers as parameters and change the values of x and y respectively. which has two instance variables.out. p3. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 7 .getpdetail().out. Product p2 = new Product(1. p2. which would set both x and y to thesame values. P_code). System. System.printf ("\nProduct Name : %S ".printf ("\nEnter Product Manufacture Name :").out.readLine()). Define a class called CartesianPoint. Provide constructors with two parameters and overload to work with one parameter as well.printf ("\n======================================="). p3.readLine (). P_name = br. x and y.printf ("\nProduct Code : %d ".out. } } class Asspro6 { public static void main(String s[])throws IOException { Product p1 = new Product().printf("\nEnter Product Name :"). Provide the methods getX() and getY() to return the values of the x and y values respectively.parseInt(br. } Public void getpdetail () { System.printf("\nProduct Manufacture Name : %S ".

getx()).x = x. System. } } class Test_Cartesian_Point { public static void main(String args[]) { Cartesian_Point s = new Cartesian_Point(0. s.println(t). this.x).20). } public String toString() { return "("+x+". } public void move(int x.println(s.int y) { this. } public Cartesian_Point(int x) { this(x.move(10.2630006 – Programming Skills IV (Java) class Cartesian_Point { int x.y = y.gety()).out.out.out. System.x). Cartesian_Point t = new Cartesian_Point(5)."+y+")".println(s). s. this.move(50). System.out.x = x.0). } public void move(int x) { move(x.out. System. } public int gety() { return y.println(s.y = y. public Cartesian_Point(int x.println(s). } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 8 . } public int getx() { return x. System. System.int y) { this. int y.out.println(s).

sqrt(c).p1.gety() p3. this. public Triangle(Cartesian_Point p1. } public String toString() { return "["+p1+":"+p2+":"+p3+"]\n".p1 = p1.sqrt(a). Similarly also define a class called Rectangle which has four CartesianPoint. double c = Math. Define a class called Triangle. b = Math. the move should take care of relatively moving the other points as well.print("["+p1+":"+p2+":"+p3+"]\n").getx()).pow((p2. class Triangle { Cartesian_Point p1. a method called rotate.p2 = p2.getx() .p3.pow((p3. Cartesian_Point p2. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 9 .out.pow((p1. this.Cartesian_Point p2.2).Cartesian_Point p3) { this. c = Math.2)+Math.pow((p2.2).pow((p3. Overload the move method to work with CartesianPoint as a parameter. } public void display() { System. double b = Math. which are of type CartesianPoint. } public void move(Cartesian_Point p1.getx() . y location. one is the CartesianPoint and other is the angle in clockwise direction. Cartesian_Point p3.p2.Cartesian_Point p2.gety() p2.getx() .gety()).2).2630006 – Programming Skills IV (Java) 8.p1.p3 = p3.gety()). Provide methods to find the area and the perimeter of the Triangle. } public double area() { double a = Math.gety()). defined in the exercise 7.Cartesian_Point p3) { this.gety() .2)+Math.getx()).p3 = p3.p2 = p2. a method display() to display the three CartesianPoints separated by ':' character.pow((p1. this. a method move() to move the first CartesianPoint to the specified x. which takes two arguments. double s =(a+b+c)/2.sqrt(b). this. a = Math.2)+Math. which has constructor with three parameters.p1 = p1. Now define a class called TestTriangle to test the various methods defined in the Triangle class.getx()).

p4. p2.gety() .Cartesian_Point p3.double angle) { } } class Rectangle { Cartesian_Point Cartesian_Point Cartesian_Point Cartesian_Point p1.p4 = p4. } public void display() Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 10 . double d = Math. //System.p4 = p4.p2 = p2.gety()).2).2)+Math. this. double c = Math.pow((p4.getx() - p3.Cartesian_Point p2.getx()). } public void move(Cartesian_Point p1.p4.out.Cartesian_Point p4) { this.getx() .gety()). p3.out.gety()).out.2)+Math. return x.p2 = p2.cd"). this.p2 = p2.gety()). p3.p4. this.pow((p2.pow((p2.out.getx() .p4 = = = = p1. this. // System.2630006 – Programming Skills IV (Java) double x = Math. public Rectangle(Cartesian_Point p1. this. p3. if(a == c || a == b || a == d ) { if( a == c && b == d) { this.2)+Math.Cartesian_Point p3.p3 = p3.pow((p1.p1.gety() - double b = Math.p1 = p1.getx()).sqrt(s*(s-a)*(s-b)*(s-c)). } public void rotate(Cartesian_Point T. } else if( a == d && b == d) { this.print("Not A Rectangle").pow((p3.out. p2.print("ab.gety() p1.p4 = p4.getx()).Cartesian_Point p4) { double a = Math.2).p2 this. this. } } else System. p4.bc").Cartesian_Point p2.pow((p1.print("\nA="+a+"\nB="+b+"\nC="+c+"\nD="+d).p1 this.2).print("ac. // System.p1 = p1.getx()). this. this.2).gety() - p2.p3 = p3.pow((p4.pow((p3. this.p3 = p3. // System.print("ad.getx() - p2. } else if( a == b && c == d) { this.p3 this.2)+Math.p1 = p1.bd").

print("AreaofT1 = "+T1.out.sqrt(c).gety() p1.pow((p2.out. System.p1.2). double d = Math.getx() .0).print("["+p1+":"+p2+":"+p3+":"+p4+"]\n").pow((p1.out.c.print("ac.b. } public String toString() { return "["+p1+":"+p2+":"+p3+":"+p4+"]\n".gety() p3.pow((p2. // System.p4.print("ab. c = Math. b = Math. a = Math.p2.getx()).gety()). } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 11 .out.pow((p4.c).2)+Math.5).pow((p3. System.print("ad.2).print(T1).area()). Cartesian_Point c = new Cartesian_Point(5. Cartesian_Point x1 = new Cartesian_Point(10).getx() . double c = Math.display().2)+Math.sqrt(b).d). } public double area() { double a = Math.2). Cartesian_Point d = new Cartesian_Point(0.sqrt(d). } else if( a == b && c == d) { // System.print(T1).sqrt(a). double b = Math.b.bc").0).getx()).gety()).out. System. return a*b.bd"). T1.p4.getx() . /*Triangle T1 = new Triangle(a.gety()).double angle) { } } class Test { public static void main(String args[]) { Cartesian_Point a = new Cartesian_Point(0.*/ Rectangle R1 = new Rectangle(a.pow((p4. } public void rotate(Cartesian_Point T.2630006 – Programming Skills IV (Java) { System.gety() .pow((p1.area()+"\n").5). return a*c.p3. System. if( a == c && b == d) { return a*b.cd"). } else return 0.out.out.gety() p2. } else if( a == d && b == d) { // System.gety()).getx() .2)+Math. Cartesian_Point b = new Cartesian_Point(5.out.2)+Math. d = Math.print("Area of Rectangle "+ R1.pow((p3.getx()).2).getx()).

this.pow((p2. equals and the hashCode methods of the classes Triangle and Rectangle defined in exercises 7 and 8 above.getx() .gety() .p3.p3 = p3. in appropriate manner.p3 = p3.2). return x. this.2)+Math.2)+Math.Cartesian_Point p3) { this. double x = Math. double s =(a+b+c)/2. } public String toString() { return "["+p1+":"+p2+":"+p3+"]\n". public Triangle(Cartesian_Point p1. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 12 .p1 = p1.p2 = p2.pow((p1. double c = Math. Override the toString.pow((p3.p2.print("["+p1+":"+p2+":"+p3+"]\n"). double b = Math.sqrt(c). and also redefine the display methods to use the toString method. } public double area() { double a = Math.gety()). a = Math. b = Math. } public void display() { System.2).2).p1.p1.gety() p3.pow((p1.getx()). class Triangle { Cartesian_Point p1.2630006 – Programming Skills IV (Java) 9.gety()).Cartesian_Point p2.Cartesian_Point p3) { this.p2 = p2.sqrt(s*(s-a)*(s-b)*(s-c)). Cartesian_Point p2.p1 = p1.pow((p3.pow((p2. this.gety()). this.getx()).sqrt(a).Cartesian_Point p2.gety() p2. } public void move(Cartesian_Point p1.getx() .getx()). Cartesian_Point p3.out.sqrt(b). c = Math.2)+Math.getx() .

p1.pow((p3. double d = Math. //System.Cartesian_Point p2.getx()). double c = Math.p1 = p1. this.p3 = p3.p4 = = = = p1.cd"). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 13 . this.out. this.out. p2.2).gety() .pow((p3.2).out.print("Not A Rectangle").getx() .getx()).out.getx()). if(a == c || a == b || a == d ) { if( a == c && b == d) { this. public Rectangle(Cartesian_Point p1.pow((p2. p4.2)+Math.p2 = p2.Cartesian_Point p3. } } else System.print("["+p1+":"+p2+":"+p3+":"+p4+"]\n"). p3.pow((p1.p4 = p4.2630006 – Programming Skills IV (Java) } public void rotate(Cartesian_Point T.p4 = p4.getx()).gety()).p1 this.getx() - p2. p3. this.getx() - p3.pow((p4. // System.gety() - double b = Math.pow((p2. } else if( a == b && c == d) { this. // System. } public void display() { System.p1 = p1.p3 = p3.2)+Math. this.out. this.double angle) { } } class Rectangle { Cartesian_Point Cartesian_Point Cartesian_Point Cartesian_Point p1. // System. p2.print("ab.bd"). p3.Cartesian_Point p2.p4.getx() .2)+Math.print("ad.p2 = p2.pow((p1.2).2)+Math. this. } public void move(Cartesian_Point p1. this.p3 = p3.p4 = p4.p3 this.bc").gety() p1.p2 this. this.pow((p4. p4.p4.gety()).p1 = p1.out.gety()).Cartesian_Point p4) { double a = Math. } else if( a == d && b == d) { this.gety()).print("\nA="+a+"\nB="+b+"\nC="+c+"\nD="+d).2).Cartesian_Point p3.print("ac.p2 = p2.Cartesian_Point p4) { this.gety() - p2.

getx() .2)+Math.getx() .pow((p3. double d = Math.getx() .b.out.sqrt(a).0).d). Define an abstract class called Polygon.2)+Math. System.c.pow((p2. } } 10.2630006 – Programming Skills IV (Java) } public String toString() { return "["+p1+":"+p2+":"+p3+":"+p4+"]\n".p3. which takes two parameters x and y to specify the destination for the first point of the Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 14 .sqrt(b). } public void rotate(Cartesian_Point T. d = Math. } else return 0.bd"). } public double area() { double a = Math. double c = Math.gety()). Cartesian_Point x1 = new Cartesian_Point(10).gety() . Declare abstract method area for this class.area()+"\n").p4. System. return a*c.b.pow((p4. Provide a constructor which takes an array of CartesianPoint as parameter.print("ac.*/ Rectangle R1 = new Rectangle(a.print("Area of Rectangle "+ R1. Cartesian_Point d = new Cartesian_Point(0.gety()). double b = Math.2).pow((p3.pow((p4.2).getx()). // System. a = Math. which calculates and returns the perimeter of the Polygon.double angle) { } } class Test { public static void main(String args[]) { Cartesian_Point a = new Cartesian_Point(0. c = Math. /*Triangle T1 = new Triangle(a. Also define a method called move.p1.area()).print("AreaofT1 = "+T1.c). return a*b.pow((p1.display(). Cartesian_Point b = new Cartesian_Point(5. Also provide method called perimeter.print(T1).gety() p3. System.sqrt(c).cd").print(T1). Cartesian_Point c = new Cartesian_Point(5.gety() p1.p2. b = Math.2)+Math.gety()).2).out. } else if( a == b && c == d) { // System.out.5).out. } else if( a == d && b == d) { // System. T1.print("ab.bc"). if( a == c && b == d) { return a*b.getx()).2).getx() .pow((p1.print("ad.0).pow((p2.out.gety() p2.5).out.2)+Math. System.getx()).p4.gety()).out.getx()).sqrt(d).

i++) s = s.gety()).Cartesian_Point p3) { x[0] = p1.pow((x[0].x[0].2)+Math. double c = Math. } public String toString() { return "["+x[0]+":"+x[1]+":"+x[2]+"]\n". Write appropriate class with main method to test the polymorphism in the area method.2)+Math.concat(""+x[i]).gety() x[1].out. public String toString() { //return ""+x[0].pow((x[2].pow((x[1]. } abstract public double area().out.getx() .sqrt(a).Cartesian_Point p2.2). this.gety()). String s = "[". public Polygon(Cartesian_Point[] x) { int i=0. return s.x[2]. double b = Math.gety()). } //System.getx()).2)+Math.concat("]").2). x[1] = p2. n = i.x[1]. a = Math. and overload to make it work for CartesianPoint as a parameter.gety() x[2]. Now update the classes Triangle and Rectangle in the exercise 8 above. } public void move(Cartesian_Point p1. for(int j=0.getx()). Enrolment No: 145253693056 - Name: Pandya Meet Pankajkumar 15 .i<n.j<n.print("["+x[0]+":"+x[1]+":"+x[2]+"]\n"). } public void display() { System. for(int i=0. s=s.2630006 – Programming Skills IV (Java) Polygon.gety() x[0].x = new Cartesian_Point[i]. to be a subclass of the Polygon class. } } class Triangle extends Polygon { public Triangle(Cartesian_Point p1[]) { super(p1).x[j] = x[j].pow((x[2].print(i).getx() .getx()).getx() . x[2] = p3.pow((x[1]. } } public int perimeter() { return n. int n. } public double area() { double a = Math.j++) { this.2).pow((x[0]. abstract class Polygon { public Cartesian_Point[] x. for(Cartesian_Point y : x) { i++.

getx() . } else if( a == b && c == d) { // System. } public void move(Cartesian_Point p1.getx()). //System.print("ad.out.2).getx() .pow((p[3]. } public void display() { System.p[2].gety() x[1]. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 16 .print("Not A Rectangle").pow((x[0].bc").2)+Math.2)+Math. x[3] = p4.out. double A = Math.2)+Math.pow((p[2].p[0].x[2].pow((x[1]. double d = Math.2).getx()).gety()).pow((p[3].pow((x[0]. } public double area() { double a = Math.getx()).getx()).pow((p[1].getx()).p[1]. double s =(a+b+c)/2. } public void rotate(Cartesian_Point T.gety() x[2].getx() .gety() p[3].out.pow((p[0]. double a = Math.gety()).pow((x[1].2).gety()). x[2] = p3.2)+Math.2).2).out. double c = Math.out.gety() p[0].pow((p[1]. double b = Math.print("ac.getx() .gety() p[2]. } else if( a == d && b == d) { // System.sqrt(b).getx() .print("ab.gety()).gety() p[1].Cartesian_Point p2.x[1].out.sqrt(c).pow((p[2]. return A. double b = Math.2)+Math.bd").print("["+x[0]+":"+x[1]+":"+x[2]+":"+x[3]+"]\n").gety()).p[3].gety()).pow((p[0].print("\nA="+a+"\nB="+b+"\nC="+c+"\nD="+d). x[1] = p2.Cartesian_Point p4) { x[0] = p1.double angle) { } } class Rectangle extends Polygon { public Rectangle(Cartesian_Point p[]) { super(p).sqrt(s*(s-a)*(s-b)*(s-c)).Cartesian_Point p3.getx() . if(a == c || a == b || a == d ) { if( a == c && b == d) { // System.2630006 – Programming Skills IV (Java) b = Math.2)+Math.2).getx()).cd"). c = Math. } } else System. } public String toString() { return "["+x[0]+":"+x[1]+":"+x[2]+":"+x[3]+"]\n".

out. } else if( a == d && b == d) { // System.gety() - x[3].0). if( a == c && b == d) { return a*b.getx()).print("ac.bc").out. a[2] = new Cartesian_Point(5.print("ad.0). a = Math. } else if( a == b && c == d) { // System.cd").out.pow((x[2].sqrt(c).print("AreaofT1 = "+T1. } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 17 .2630006 – Programming Skills IV (Java) double c = Math.out.print(R1).print("AreaofR1 = "+R1. x[0].print(T1).2)+Math.5).pow((x[3]. a[3] = new Cartesian_Point(0.2). a[1] = new Cartesian_Point(5. } else return 0.double angle) { } } class Test { public static void main(String args[]) { Cartesian_Point a[] = new Cartesian_Point[5].gety()).area()+"\n"). c = Math.area()+"\n").5). a[2] = new Cartesian_Point(5.sqrt(b). System. System.out. return a*b.5). return a*c.getx() - x[0].pow((x[3]. a[0] = new Cartesian_Point(0. System.0).gety()). Rectangle R1 = new Rectangle(a).pow((x[2].sqrt(d).gety() - double d = Math. Polygon T1 = new Triangle(a). // System.getx() - x[3]. a[0] = new Cartesian_Point(0. System.2).getx()). a[1] = new Cartesian_Point(5. b = Math.out. } public void rotate(Cartesian_Point T. d = Math.2)+Math.out.0).print("ab.sqrt(a).bd").

geometry.gtu.2)+Math.out. public class Triangle extends Polygon { public Triangle(Cartesian_Point p1[]) { super(p1). } public void move(Cartesian_Point p1.2)+Math.double angle) { } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 18 .gety() x[0]. Use appropriate access specifiers for the classes and the members of the classes defined in the earlier exercises.2).x[0].sqrt(c).pow((x[2].pow((x[1].2)+Math. double s =(a+b+c)/2.gety() x[2].Cartesian_Point p2.Cartesian_Point p3) { x[0] = p1.gety()). } public String toString() { return "["+x[0]+":"+x[1]+":"+x[2]+"]\n". double c = Math.geometry.sqrt(b). x[1] = p2. Now onwards all the classes must be defined in a package.2630006 – Programming Skills IV (Java) 11.gety()).getx()). } public double area() { double a = Math.sqrt(a).x[2].getx() . belong to a package called edu.sqrt(s*(s-a)*(s-b)*(s-c)).print("["+x[0]+":"+x[1]+":"+x[2]+"]\n"). } public void display() { System. TestTriangle.x[1].geometry.gtu.gety() x[1]. the classes Polygon. TestRectangle and TestPolygon belong to the package edu. package mca.getx()). b = Math.gety()).third. Triangle and Rectangle belong to the package edu.pow((x[0].shapes and the classes TestCartesianPoint. } public void rotate(Cartesian_Point T.2).getx()).gtu. double b = Math.getx() .getx() . Make the class CartesianPoint.pow((x[0].pow((x[2]. a = Math. c = Math. x[2] = p3.pow((x[1]. double A = Math.test. return A.2).

System.getx()). Polygon T1 = new Triangle(a).java package mca. double d = Math.getx()).2).geometry.getx() . a[2] = new Cartesian_Point(5.2630006 – Programming Skills IV (Java) } Test.Cartesian_Point p2.Cartesian_Point p3.5).2). System.gety()). class Rectangle extends Polygon { public Rectangle(Cartesian_Point p[]) { super(p).out.gtu.print(T1).geometry.print(R1).2)+Math.pow((p[0].*.p[3].print("Not A Rectangle").pow((p[1].0).print("AreaofT1 = "+T1.java import edu.gety()). System.cd").gety() p[3].print("ad.2)+Math.Cartesian_Point p4) Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 19 .out.out. //System. double a = Math.2).2)+Math.p[0].0).pow((p[2]. a[1] = new Cartesian_Point(5.out.out.pow((p[3].out. Rectangle R1 = new Rectangle(a).pow((p[3].area()+"\n").pow((p[0].gety() p[2]. class Test { public static void main(String args[]) { Cartesian_Point a[] = new Cartesian_Point[5].out.out. a[2] = new Cartesian_Point(5.bd").getx() .area()+"\n").pow((p[1]. } else if( a == d && b == d) { // System.gety()). } } else System.gety() p[1].pow((p[2].p[2].p[1].print("ab.out.2).0).getx() .5).third.0).print("ac.getx()). } } Ractangle. a[0] = new Cartesian_Point(0.gety() p[0].bc"). double c = Math. if(a == c || a == b || a == d ) { if( a == c && b == d) { // System.5).getx()). a[0] = new Cartesian_Point(0.getx() . a[1] = new Cartesian_Point(5. double b = Math.2)+Math. } public void move(Cartesian_Point p1. } else if( a == b && c == d) { // System.print("\nA="+a+"\nB="+b+"\nC="+c+"\nD="+d). a[3] = new Cartesian_Point(0.gety()).print("AreaofR1 = "+R1. System.

p4.x[3].bd"). } public void rotate(Cartesian_Point T.gety() x[0].pow((x[3].pow((x[2]. for(Cartesian_Point y : x) { i++.2630006 – Programming Skills IV (Java) { x[0] x[1] x[2] x[3] = = = = p1.2)+Math.java package mca.getx()). } else return 0.gety()).pow((x[0].x[1].getx() .third. } else if( a == b && c == d) { // System. p2.gety() x[3].sqrt(a).getx()). return a*b.pow((x[1].out. b = Math. c = Math.getx() .out.print("ac.pow((x[0]. return a*c.double angle) { - } } Polygon. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 20 .print("["+x[0]+":"+x[1]+":"+x[2]+":"+x[3]+"]\n"). } public String toString() { return "["+x[0]+":"+x[1]+":"+x[2]+":"+x[3]+"]\n".gety() x[2].sqrt(d).pow((x[3]. } public void display() { System.getx() .pow((x[1].bc").getx()).out. // System.x[2]. a = Math.2)+Math. int n.2).print("ab. abstract class Polygon { public Cartesian_Point[] x.gety()).2)+Math. } public double area() { double a = Math.gety()).cd").2). double d = Math.x[0].sqrt(c).geometry.print("ad. double c = Math. double b = Math. p3.2).getx() .2). } else if( a == d && b == d) { // System. d = Math.sqrt(b).gety() x[1].getx()).2)+Math.pow((x[2]. if( a == c && b == d) { return a*b.out. public Polygon(Cartesian_Point[] x) { int i=0.gety()).

} public Cartesian_Point(int x) { this(x. } abstract public double area(). } public int gety() { return y. public String toString() { //return ""+x[0]. } public String toString() { return "("+x+". } } public int perimeter() { return n.y = y.j<n.x).i<n.java package mca.i++) s = s.geometry.third.x = x. n = i.int y) { this.x). } public int getx() { return x.j++) { this. String s = "[".x[j] = x[j].2630006 – Programming Skills IV (Java) } //System. return s. public Cartesian_Point(int x.concat("]").x = x. int y.concat(""+x[i]).y = y. } } Cartesian_point.int y) { this. public class Cartesian_Point { int x."+y+")". } public void move(int x) { move(x. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 21 . s=s.x = new Cartesian_Point[i].out. } public void move(int x. this. this. this. for(int j=0. for(int i=0.print(i).

0). a[0] = new Cartesian_Point(0.area()+"\n"). a[4] = new Cartesian_Point(8. // // a[0] = new Cartesian_Point(0. to throw an exception if the CartesianPoint instances passed as parameter does not specify an appropriate Triangle or Rectangle. import edu. Rectangle R1 = new Rectangle(a).out.gtu.out. System.5).geometry. eg. or in case of Rectangle.*. In case of Triangle.print("AreaofT1 = "+T1. Polygon T1 = new Triangle(a). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 22 . a[2] = new Cartesian_Point(5. a[1] = new Cartesian_Point(5. System. a[2] = new Cartesian_Point(5.out.print(R1). a[3] = new Cartesian_Point(8. } } DemoException. System. } public String toString() { return msg.print("AreaofR1 = "+R1.2630006 – Programming Skills IV (Java) } 12. Update the classes Triangle and Rectangle.5). class Test { public static void main(String args[])throws DemoException { Cartesian_Point a[] = new Cartesian_Point[4].5).6).0).print(T1).0). System.third.0). public class DemoException extends Exception { public DemoException(String msg) { super(msg).out.area()+"\n"). a[1] = new Cartesian_Point(5.geometry. if the three points are in a straight line. if the lines when connected cross each other.java pacakge mca.

Define a class called PolygonManager. interface input { BufferedReader br =new BufferedReader(new InputStreamReader(System. remove and list the Polygon instances managed by it. } class triangle extends polygon_manager { triangle() { } triangle(int xy) { super(xy). polygon_manager() { } polygon_manager(int xy) { x=new int[xy]. Provide methods to add. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 23 .println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->").io.in)). } abstract void display(). } void add()throws IOException { System.println("\nEnter the Three Co-Ordinates :"). int i. y=new int[xy].2630006 – Programming Skills IV (Java) } } 13.*.out. } abstract class polygon_manager implements input { int x[]. import java. size=xy.Test the methods of PolygonManager by writing appropriate class with main method. int size. i=0. for(i=0.out.i++) { System. which manages a number of Polygon instances. int y[].i<3.

print("}").readLine())."+y[i]+")").i++) Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 24 .out. } } class rectangle extends polygon_manager { rectangle() { } rectangle(int xy) { super(xy).i++) { System.out.println("\nEnter the five Co-Ordinates :"). x[i]=Integer.parseInt(br.parseInt(br. y[i]=Integer.out.print("("+x[i]+".parseInt(br.out.parseInt(br. for(i=0.{").parseInt(br.2630006 – Programming Skills IV (Java) x[i]=Integer. } void add()throws IOException { System. y[i]=Integer. } void add()throws IOException { System. } } void display() { System.i++) { System.i<3. } } void display() { System.print("}"). for(i=0.readLine()).parseInt(br.out.out.i<4.out.readLine()). x[i]=Integer."+y[i]+")").readLine()). } System.out. } System.print("\n\tTriangle :.i<5.readLine()).print("("+x[i]+".print("\n\tRectangle :.out.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->"). } } class pantagon extends polygon_manager { pantagon() { } pantagon(int xy) { super(xy). for(i=0.i<5.readLine()).println("\nEnter the four Co-Ordinates :"). y[i]=Integer.out. for(i=0.i<4.i++) { System.{"). for(i=0.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->").i++) { System.{").print("\n\tPantagon :. } } void display() { System.

print("\n\tOctagon :. } } class polygon implements input Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 25 . for(i=0.out.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->").parseInt(br.out.out. } void add()throws IOException { System.print("("+x[i]+".readLine())."+y[i]+")"). } System. x[i]=Integer.print("}").print("}").println().i<8. x[i]=Integer."+y[i]+")").parseInt(br.i++) { System."+y[i]+")"). y[i]=Integer.print("("+x[i]+".out.parseInt(br.out.out. for(i=0.i++) { System.i<6.out.i<6.readLine()).2630006 – Programming Skills IV (Java) { System.println("Enter the x"+(i+1)+" And Y"+(i+1)+"=->"). for(i=0.print("\n\tHexagon :. } System.out.i++) { System.print("("+x[i]+". for(i=0.out.println("\nEnter the six Co-Ordinates :").readLine()).{").out. } } class octagon extends polygon_manager { octagon() { } octagon(int xy) { super(xy).readLine()). } } void display() { System. } void add()throws IOException { System.print("}").println("\nEnter the Eight Co-Ordinates :").i<8.{"). } } class hexagon extends polygon_manager { hexagon() { } hexagon(int xy) { super(xy).i++) { System.out. y[i]=Integer. } } void display() { System.parseInt(br.out. } System.out. System.

. t.readLine()).add().. ch=Integer. default : System.."). for(j=0. p[len]=t.. p[len]=pa..out.println("4. polygon_manager p[]=new polygon_manager[100].. } System.. len++.. case 2 : if(len<1) { System...j=0.out.2630006 – Programming Skills IV (Java) { public static void main(String arg[])throws IOException { int ch.j<len.. case 5: octagon o=new octagon(8). r.Display").....parseInt(br. break...pos. case 4: hexagon h=new hexagon(6).out...out. switch(ch) { case 1: triangle t=new triangle(3). while(true) { System. len++.").readLine()).. System.out.out. break. o. pa...Exit")...parseInt(br.len=0... System....... case 3: pantagon pa=new pantagon(5). System.. } break.println("\nFunction Of Polygon. ch=Integer..println("\nPolygon does not exists....out... break. p[len]=h.. switch(ch) { case 1: menuformat(). System.out...Add").add().. break.out. break...j++) Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 26 .println("1. case 2: rectangle r=new rectangle(4).").. len++.add(). len++.. p[len]=o. break. p[len]=r. case 6: break. len++.add().. System.println("Enter Your Choice =->").Remove").add().println("\nPlz Enter 1 To 6 . h.println("\nList Of Polygon Is .")... break.println("2.println("3.

} } else { System...out......out. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 27 .....println("\nEnter The Position =->").. if(pos<len) { if(p[pos-1]....out..println("\nEnter The Position =->"). if(pos<len) { if(p[pos-1].........parseInt(br..readLine())...... switch(ch) { case 1: System..out..out....out.size==4) { p[j]=null.. pos=Integer.").. } else { System.println("\nInvalid Selection.parseInt(br.. if(pos<len) { if(p[pos-1]........display()..... ch=Integer.... } } else { System.... pos=Integer..... } break..readLine()). } else { System....out. case 4: System.println("\nInvalid Selection.println("\nInvalid Position.")..size==5) { p[j]=null..println("\nEnter The Position =->")...println("\nInvalid Selection...2630006 – Programming Skills IV (Java) { p[j]. } break.out. pos=Integer.readLine()).parseInt(br.println("\nInvalid Position. case 3: System.").out..size==3) { p[j]=null......println("\nInvalid Position...readLine())."). } menuformat().... case 2: System. } } else { System.. } else { System.....parseInt(br...out..."). } break.println("\nEnter The Position =->")..").

println("2.... case 4 : return .println("\nList Of Polygon Is ........out.size==6) { p[j]=null..println("\nInvalid Selection.. } break. System.")..display(). } } else { System.. System.....out..out.. } } } public static void menuformat() { System.out... System.").out.......Hexagon")...2630006 – Programming Skills IV (Java) pos=Integer. case 5: System. for(j=0........readLine())..out.. case 6: break..")...out.out...out.... } else { System.....readLine()).......println("6..parseInt(br.out.println("5.println("\nEnter The Position =->").Tringle").."). } break..Rectangle")....println("\nInvalid Position.").. } } else { System. case 3 : System..println("1.. System.println("\nInvalid Position.... pos=Integer...println("\nPlz Enter 1 To 6 . if(pos<len) { if(p[pos-1].....j<len...out..... Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 28 .println("4..parseInt(br... if(pos<len) { if(p[pos-1]....Back To Main Menu.....").size==8) { p[j]=null...println("3....out...println("\n\nSelect Any Polygon...Pantagon")... System..out.. } break. } else { System..").out.. } break... System..").Octagon")... default : System.println("\nInvalid Selection....j++) { p[j]... break.

io. mode import java.readLine()). import java. System. try{ vname = br.io.i++) Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 29 .printf("How many values You want to Enter? "). a method to reset the entire data. System.InputStreamReader. } catch(IOException e) { System. vname="". } 14.println("Error while Reading from console").readLine().out.out.BufferedReader.N. public StatisticalData() { N=0.out. mean 2.out.printf("Enter variable Name and its values: "). try{ N=Integer. String vname. for(i=0.println("Enter Your Choice =->"). median 3.2630006 – Programming Skills IV (Java) } System. a method add to individually add data of type int. import java. class StatisticalData { int v[].parseInt(br. } public void setData() { BufferedReader br=new BufferedReader(new InputStreamReader(System.io.in)). Provide a method to setData available in the form of an array. int i. } v=new int[N].i<N. Define a class called StatisticalData which manages a number of readings of type int.IOException. and methods to return the following statistics: 1.

m=temp[x]. for(i=0.j. System. } public double Mean() { double m=0.out. } System.n=N-1.print("Your Data are: ").println().out.j<n-i. int i. m=m/2. int temp[]=new int[N]. } } catch(IOException e) { System. return m.println("Variable Name: " + vname). m=temp[x].i<n. } } } if(N%2 == 0) { x=N/2. int i. } else { x=N/2.i++) { System.parseInt(br.i++) { for(j=0.i<N. for(i=0.print(" " + v[i]). } public double Median() { double m=0. x--.i++) { m=m+v[i]. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 30 . } return m.i<N. temp[j+1]=x. temp[j]=temp[j+1].out. } for(i=0. } m=m/N.x.2630006 – Programming Skills IV (Java) { v[i]=Integer.readLine()). System. for(i=0.i++) { temp[i]=v[i].out.out. } System.println("IND: " + x).j++) { if(temp[j] > temp[j+1]) { x=temp[j].println("Error while Reading from console").i<N.out. m=m+temp[x].

i++) { temp[i]=v[i]. if(P-n > 0) { i=(int)P. P=Math.2630006 – Programming Skills IV (Java) public double Mode() { double M. sd=Variance().m. return m.m.j. else { P=p. temp[j]=temp[j+1]. return sd. } for(i=0. int i. int i.0. n=P*n/100. } public double Variance() { double var=0.x. } public double StdDev() { double sd. sd=Math.i++) { var=var+(v[i]-m)*(v[i]-m). for(i=0.n. double P.ceil(n). return var.j++) { if(temp[j] > temp[j+1]) { x=temp[j].i++) { for(j=0.i<N.i<N. P=temp[i-1]. int i. int temp[]=new int[N]. temp[j+1]=x. M=Median(). } var=var/(N-1). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 31 . n=N.x.sqrt(sd).j<N-i-1. m=Mean(). for(i=0. } } } if(p==100) return temp[N-1]. } public double Percentile(int p) { if(p==0) return 0. m=3*M-2*x.i<N-1. x=Mean().

println("Mode: " + result). case 3: result=s. System.Variance().out.out.println("Median: " + result). case 6: result=s.Mean(). break. System. Set Data"). P=temp[i]+temp[i-1]. int ch=10.out.out. Variance").3)").out.out.p=-1. System. Quartile (between 1 . break.println("8.setData().Mode().println("1.println("2.println("10.out.out.println("Variance: " + result). System.println("Error while Reading from console"). System.parseInt(br.setData(). double result. switch(ch) { case 1: s.2630006 – Programming Skills IV (Java) } else { i=(int)P. System.println("4. break. System.println("5.print("Enter Your Choice: ").out.out.out. break. System. } catch(IOException e) { System. System.out. System.in)).out. System. } } } class P14 { public static void main(String args[]) { BufferedReader br=new BufferedReader(new InputStreamReader(System.100)"). System. } return P.Median(). P=P/2.StdDev(). System.readLine()). case 4: result=s. s.println("9. System. Percentile (between 0 . case 5: result=s. StatisticalData s=new StatisticalData(). try{ ch=Integer.out.ch1=1.println("7.println("6.out. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 32 . } }while(ch<1 || ch>10). Mean"). case 2: result=s. Standard Deviation"). Median"). Exit"). do { do { System.out.Q3. Interquartile Range").println("3. break.println("Mean: " + result). Mode").

out.print("Enter Your Choice: ").parseInt(br.println("Error while Reading from console"). System. case 2: result=s. } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 33 .println("1. result=s.out. System.out.out.print("Which Percentile you want to calculate? ").out. } }while(ch != 10).out.println("2.println("Standard Deviation: " + result). result=s.readLine()). } }while(ch1<1 || ch1>3).out. result=Q3-result.println("Percentile: " + result). case 7: do { System. } }while(p<0 || p>100).println("3.out. System.Percentile(75).Percentile(25). case 3: result=s. switch(ch1) { case 1: result=s.Percentile(75).println("Error while Reading from console").out. } catch(IOException e) { System. First "). System. System. System. } catch(IOException e) { System. case 8: do { System. System.out. break.out. } break.println("First Quartile: " + result). System. Third ").out. case 9: Q3=s.out. break. try{ ch1=Integer.println("Inter Quartile Range: " + result).println("Second Quartile: " + result).parseInt(br. try{ p=Integer.Percentile(25).Percentile(50).2630006 – Programming Skills IV (Java) System.Percentile(p).println("Third Quartile: " + result). break. break. Second ").readLine()).

out...out..readLine()).out... in a comma separated form.. } void add()throws IOException{ if(n==60) { System.in)). Test the new methods using appropriate data. } else{ marks[n]=temp.println("There is 60 student in the class. for(int i=0.. n++.").out. int n.100.parseInt(br. Update the class StatisticalData.*.println("You can't enter any more marks. where numeric data is available in an ASCII format..").2630006 – Programming Skills IV (Java) 15.i++){ Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 34 . StatisticalData(){ marks=new int[60].out. and define a method called loadFromCSV. n=0. class StatisticalData { BufferedReader br=new BufferedReader(new InputStreamReader(System.").println("Marks can't be the String.util. } else{ System. import java. } } } float mean() { display().. try{ int temp=Integer.. which takes as parameter an InputStream."). import java.io... int marks[].. System.. OR can not leave it blank.i<n.. Overload this method to take a File instance as parameter.print("Enter Mark of Student : "+(n+1)+" : "). add(). } } catch(NumberFormatException nfe) { System.*.. add(). float sum=0.println("Marks should be in range between 0 . if(temp>100 || temp<0) { System.

println(m). System. for(int j=i+1.i<n.println(marks[i]).k++){ if(count[k]>temp) { temp=count[k].out. } float standard_deviation(){ float variance = variance(). } } System.out. } return (sum/((n-1)*1. display(). float sum=0. } float median(){ sort()..2630006 – Programming Skills IV (Java) sum+=marks[i].out.println((marks[i]-mean)+" | "+((marks[i]-mean)*(marks[i]mean))). System. } } } } float variance(){ float mean=mean(). for(int i=0.0f))..0f*median())-(2.i++){ System.0f. int tmp=(n+1)/2. } int specified_percentile(int nth) { Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 35 . if(temp1==-1) { m=(3.0f)). sum+=(marks[i]-mean)*(marks[i]-mean). if(n%2==0) { med=(marks[tmp-1]+marks[tmp])/2.i++){ if(count[i]==temp) { System.j<n. int temp1=-1. } else{ for(int i=0.println("\n\n (X-Xbar) | (X-Xbar)^2 \n").println("Mode is/are . float m=0.out.k<n. for(int i=0. } } } int temp=1. return ((float)(Math.sqrt(variance))). for(int k=0. } return med.0f*mean()). float med=0.. } void mode(){ display().0f.j++){ if(marks[i]==marks[j]) { count[i]++.out.i<n. int count[]=new int[n].. } else { med=marks[tmp-1]. temp1=k. } return (sum/(n*1.i++){ count[i]=1.").i<n.

if(k==0.add(istr).get(0).. } else{ fis=(FileInputStream)v. } else{ System.1).. } void loading_process(Vector v.. } if(asc==44 || asc==13) { int t=Integer. m[i]=t.i=0..read(). is not Accepted").get(0).println("Your Data is as Bellow . char[] str=new char[1].0f . String temp2="". int m[]=new int[60]. loading_process(v1.2630006 – Programming Skills IV (Java) sort().. } float interquarlite_rang(){ return (specified_quertile(3)-specified_quertile(1)). while(asc!=-1) { if(ch1==0) { asc=istr.println(t+" is not valid Mark."). } else{ int i=(int)Math.add(fis).out. int i=(int)Math. v...0f). return (marks[i-1]). } float specified_quertile(int nth) { sort(). sq=((marks[i-1]+marks[i-2])/2. FileInputStream fis=null. float k=temp%t.ceil(temp). i++. display().")..ceil(((nth*(n))/100.println(t+" is Accepted.. } void load_from_csv(InputStream istr) throws IOException{ Vector v1=new Vector().0f)).0). } void load_from_csv(File f) throws IOException{ FileInputStream fis=new FileInputStream(f). } else{ asc=fis. if(t>100 || t<0) { System.out.out.0f). if(ch1==0){ istr=(InputStream)v.read(). float sq=0. int t=(int)(temp). System.parseInt(temp2). display(). Vector v=new Vector(). } return sq. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 36 .. float temp=((nth*(n+1))/4.int ch1) throws IOException{ InputStream istr=null. v1.0f) { sq=marks[t-1]. } int asc=0. loading_process(v.

println(m[j]).").. } else{ if(asc>=48 && asc<=57) { str[0]=(char)asc.").println("Enter Y (for Yes) \nEnter N (for No)...println("\nYour previous data is as it is..equalsIgnoreCase("N")){ if(ch.. } else if(ch. } } } System..").. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 37 .print(marks[i]+" "). StatisticalData s=new StatisticalData(). marks[j]=temp. } } } } void display(){ System.in)).. String temp3=new String(str)... System. while(k==0) { System.. marks=m.out.. } } class p15{ public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System. String ch=br. n=i.\n").print("\nSure you want to import this data ? (Y/N) :").concat(temp3). System..out.out..println("\nYour Data is Successfully imported.. for(int i=0.....j<n. } int get_size(){ return n.i<n.j++){ if(marks[i]>marks[j]) { int temp=marks[i].out.equalsIgnoreCase("N")){ System.readLine()..println("\n Your Data is .println("\n"+n+" Student's Mark imported.").out.2630006 – Programming Skills IV (Java) } temp2="".equalsIgnoreCase("Y")){ marks=new int[60]. marks[i]=marks[j]. if(ch."). temp2=temp2.out.println("")...out.out.out.j<i. } else{ System. } System.i++){ System.i<n.. } } } void sort(){ for(int i=0.\n Importation of data has been cancelled. \nOtherwise System can't recognize.println("Your meaningfull data from CSV file found as follow.i++){ for(int j=i+1. for (int j=0. int ch=1. } int k=0. } k=1.equalsIgnoreCase("Y") || ch....j++){ System.out.

break. Standard Deviation"). } else if( ch != 0 ) { System. OR can not leave it blank. break.println("\nMain Menu").println("11. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 38 .. System. case 4: s..out.out. } System. ch=13.. System. break. Exit").mean()). } if(s.. System. Otherwise System can't recognize.out.. Variance"). Specified Percentile").equalsIgnoreCase("Y") || ch1.out..out.readLine()).. Median").out.out.out.mode().println("Median : "+s. } break..add().out.println("07.. case 6: System.out. try{ ch=Integer. break.re-enter your selection.println("0. System. } else{ System. } catch(NumberFormatException nfx) { System."). break.println("System can't recognize your choice.println("06. Mode")..println("03.median()).get_size()==0 && ch!=1 && ch!=10 && ch!=11) { if(ch>11) { System.out. Insert Mark").")..println("Enter Y (for Yes) \nEnter N (for No).. case 5: System. System.out.out.out. System. System.println("09. while(ch1. case 3: System.out. System.out. Interquartile Range"). System.compareToIgnoreCase("N")!=0){ if(ch1. Specified Quarlite").out. Load Data from CSV file ( using Input Stream )").println("05. System.print("Want to add more ? (Y/N) :")..println("08.out.readLine(). case 7: int flag=0. case 2: System. Load Data from CSV file ( using File )").println("10."). System..standard_deviation())..equalsIgnoreCase("N")){ s.println("01.. } } else{ switch(ch) { case 1: String ch1="Y".println("Mean : "+s.print("Enter your choice :").println("02.").variance())..println("04.2630006 – Programming Skills IV (Java) while(ch!=0){ System.println("Enter the mark of student first.out. System..parseInt(br.out. System.out.out.println("Standard Deviation : "+s. ch1=br..println("Variance : "+s.println("You can not enter the string.out. Mean").

2630006 – Programming Skills IV (Java)
while(flag==0) {
try{
System.out.print("Enter value for Specified Percentile (0100) :");
int p=Integer.parseInt(br.readLine());
if( p > 100 || p < 1 ) {
System.out.println("Enter between 1 - 100 .....");
}
else{
System.out.println("Specified Percentile for intput " + p + "
is : "+s.specified_percentile(p));
flag=1;
}
}
catch(NumberFormatException e) {
System.out.println("Enter between 1 - 100 .....");
}
}
break;
case 8:
flag=0;
while(flag==0) {
try{
System.out.print("Enter Value for Specified Quarlite (13) :");
int q=Integer.parseInt(br.readLine());
if( q > 3 || q < 1) {
System.out.println("Enter between 1 - 3 ......");
}
else{
System.out.println("Specified Quarlite for input "
+ q + " is : "+s.specified_quertile(q));
flag=1;
}
}
catch(NumberFormatException e){
System.out.println("Enter between 1 - 3 ......");
}
}
break;
case 9:
System.out.print("Interquartile Range : "+
s.interquarlite_rang());
break;
case 10:
flag=0;
String path="";
while(flag==0) {
try{
System.out.print("Enter the Path for csv file :");
path=br.readLine();
String ext=path.substring(path.length()-4);
if(ext.equalsIgnoreCase(".csv")){
InputStream istr=new FileInputStream(path);
s.load_from_csv(istr);
istr.close();
flag=1;
}
else{
System.out.println("System can't recognize your input....");
System.out.println("System can support only .CSV file....");
}
}
catch(FileNotFoundException e) {
System.out.println("System can't find your inputed path....");
}

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar 39

2630006 – Programming Skills IV (Java)
catch(StringIndexOutOfBoundsException e){
System.out.println("Can't leave it blank...");
}
}
break;
case 11:
flag=0;
path="";
while(flag==0) {
String ext="";
try{
System.out.print("Enter the Path for csv file :");
path=br.readLine();
ext=path.substring(path.length()-4);
}
catch(StringIndexOutOfBoundsException e){
System.out.println("Cannot be Blank");
}
if(ext.equalsIgnoreCase(".csv")) {
try{
File f=new File(path);
s.load_from_csv(f);
flag=1;
}
catch(FileNotFoundException e) {
System.out.println("System can't find your inputed path....");
}
}
else{
System.out.println("System can't recognize your input....");
System.out.println("System can support only .CSV file....");
}
}
break;
case 12:
s.display();
break;
case 0:
break;
default:
System.out.println("System can't recognize your choice, reenter your selection....");
break;
}
}
}
}
}

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar 40

2630006 – Programming Skills IV (Java)

16. A college maintains the information about the marks of the students of a class in a text file with
fixed record length. Each line in the file contains data of one student. The first 25 characters have
the name of the student, next 12 characters have marks in the four subjects, each subject has 3
characters. Create a class called StudentMarks, which has studentName, and marks for four
subjects. Provide appropriate getter methods and constructors, for this class. Write an application
class to load the file into an array of StudentMarks. Use the StatisticalData class to compute the
statistics mean, median, mode for each of the subjects in the class.
import java.io.*;
import java.util.*;
class Student_Marks
{
int Rollno;
String stu_name;
int sub_marks[] = new int[5];
Student_Marks()
{}
Student_Marks(int Rollno,String stu_name,int mark1,int mark2,int mark3,int mark4,int
mark5)
{
this.Rollno = Rollno;
this.stu_name = stu_name;
sub_marks[0] = mark1;
sub_marks[1] = mark2;
sub_marks[2] = mark3;
sub_marks[3] = mark4;
sub_marks[4] = mark5;
}
public void getdata()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Rollno: ");
this.Rollno = Integer.parseInt(br.readLine());
System.out.print("Enter Name: ");
this.stu_name = br.readLine();

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar 41

sub_marks[0].print("Enter Marks["+(i+1)+"] : ").add(temp).%-25S. for(int i=0. temp = new Student_Marks(1.add(temp).2630006 – Programming Skills IV (Java) for(int i=0.sub_mar ks[3].i<5.i++) { System. s1.70.30. } public int getRollno() { return Rollno.get(i)). temp = new Student_Marks(1.stu_name. } public String toString() { return Rollno+".20). return sum.add(temp).sub_marks[2].this.add(temp).%3d."Amit"."Suresh".40.this.40).20.60)."+sub_marks[2]+ ".40. s1.writedata().40.%3d. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 42 .60.parseInt(br. } } public int getmark(int i) { return sub_marks[i].30).%3d.this.this. out.i<s1.30. this. temp = new Student_Marks(1.i++) { System.this."+sub_marks[3]+ ".readLine()).%3d.out. } public int getTotal() { int sum = 0.add(temp). out."+sub_marks[1]+ ". Statistical_data sd = new Statistical_data(). } public String getName() { return stu_name. for(int x : sub_marks) sum += x.println(s1.20.Rollno."Mahesg".60.out. s1."Amit".40."+sub_marks[4].printf("%3d. s1.30. %3d"."+stu_name+".40.30. s1."+sub_marks[0]+ ".sub_marks[4]).sub_marks[i] = Integer. } public void writedata()throws IOException { FileOutputStream fos = new FileOutputStream("F:\\Anand.40). Student_Marks temp = new Student_Marks(1.size()].40. } float sub_mark[][]= new float[5][s1.txt". } } class Application { public static void main(String args[]) throws IOException { ArrayList<Student_Marks> s1 = new ArrayList()."Paresh". s1.this. temp = new Student_Marks(1.true). PrintStream out = new PrintStream(fos).60.20.println().get(i).40.size().40.20.sub_marks[1].this.

System.println("\nDetails of sub4").2f".sd. System.sd.printf("\nquartile %3.out.mean()).printf("\nquartile %3.sd.out. System.percentile(20)).i<s1.out.median()).sd.variance()). } sd.2f". sub_mark[3][i] = s1.out.quartile(2)).2f".println("\nDetails of sub2").get(i).out.2f". System.2f".printf("\nquartile %3. System.printf("\nVARIANCE %3.SD()).printf("\nSD %3. System.printf("\nMEAN %3.get(i).out.out.out.sd.2f".printf("\nVARIANCE %3.printf("\nSD %3.set(sub_mark[4]).sd.sd. System. System.printf("\npercentile %3. System. System.2f". System.mean()).mean()). System.percentile(20)).printf("\nIQR %3. System. System.2f".SD()). sd. System. System. System.printf("\npercentile %3. System. System. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 43 .sd.sd.sd. System.out.2f".out.out.2f".print("=========================================").sd.out.out.2f".2f".out. System. System.median()).2630006 – Programming Skills IV (Java) for(int i=0.printf("\nMEDIAN %3.2f".set(sub_mark[2]).2f".out.sd.i++) { sub_mark[0][i] = s1.printf("\nMODE %3.out.sd.2f".printf("\nMODE %3.IQR()).2f".printf("\nMEAN %3.printf("\nMEDIAN %3.percentile(20)).sd.2f".quartile(2)).printf("\nquartile %3.out.printf("\nMEAN %3.print("=========================================").median()).mode()). sub_mark[1][i] = s1. sd.2f".printf("\nSD %3.sd.printf("\nMEAN %3. System.out. System.sd.sd.IQR()).sd. System.out.printf("\nMEDIAN %3.printf("\nMEDIAN %3. System.out.getmark(2).2f".sd. System.median()).sd.mode()).sd. System. System.out.out.printf("\nVARIANCE %3.printf("\nMODE %3.get(i).out. System.mode()). System.printf("\nMEDIAN %3.sd.2f".printf("\nMODE %3. System.getmark(4).2f".2f".out.out.sd. sd.IQR()).print("========================================="). System.out.2f".sd.2f".out.printf("\nVARIANCE %3.out.2f".variance()).printf("\nSD %3.2f".variance()).sd.get(i).mode()).sd.sd. System. System.sd.sd.2f".size().2f".median()).getmark(1).2f".out.out.2f".println("\nDetails of sub1"). sub_mark[4][i] = s1.out.2f".printf("\nMODE %3.printf("\nMEAN %3. System.out.printf("\nSD %3. System.sd.printf("\nIQR %3.set(sub_mark[0]).2f". System.print("=========================================").2f".percentile(20)).quartile(2)).out.sd.out.sd.mean()).out.sd.out.sd.printf("\nIQR %3.SD()).println("\nDetails of sub3").out. System.mode()).out.getmark(0).set(sub_mark[1]).sd.sd.print("=========================================").getmark(3).SD()). System.2f".out.out.out. System.out.printf("\npercentile %3.out.variance()).mean()).2f".println("\nDetails of sub5").out.printf("\nVARIANCE %3.out. System.sd. System. sd.quartile(2)).out.variance()).printf("\npercentile %3. System.out.printf("\nIQR %3.SD()).IQR()). System.2f". System.set(sub_mark[3]).get(i).2f". sub_mark[2][i] = s1. System.

out.out.printf("\nIQR %3. } } 17.sub_marks[i] = Integer. } } public int getmark(int i) { return sub_marks[i].sd.print("Enter Marks["+(i+1)+"] : ").percentile(20)). Student_Marks() {} Student_Marks(int Rollno.sd.i<5.int mark5) { this.*. this.io.quartile(2)). use multithreading.IQR()).int mark4. this. System. import java.parseInt(br.stu_name = br.Rollno = Rollno. String stu_name.out.readLine(). sub_marks[2] = mark3. } public void getdata()throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System. sub_marks[1] = mark2. this.printf("\nquartile %3.out.sd.out.Rollno = Integer.in)). int sub_marks[] = new int[5].print("Enter Rollno: ").stu_name = stu_name.2f".i++) { System. for(int x : sub_marks) Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 44 . sub_marks[4] = mark5.*.String stu_name.readLine()). after loading the StudentMarks from the file. to compute the statistics.int mark1. sub_marks[3] = mark4. sub_marks[0] = mark1. class Student_Marks { int Rollno. Create atleast five files in a directory with fixed record length to test your code.print("Enter Name: "). System.out.int mark2.2630006 – Programming Skills IV (Java) System. System. for marks information available for different classes available from files placed in a directory. this.readLine()).2f".int mark3. System.parseInt(br. for(int i=0.printf("\npercentile %3. import java. } public int getTotal() { int sum = 0.2f".util. In the above exercise.

temp = new Student_Marks(1.get(i). out.30.i++) { System.stu_name.Rollno. } public void writedata()throws IOException { FileOutputStream fos = new FileOutputStream("F:\\Anand.40.10.40.10.10.40.30. s1. for(int i=0.get(i). s1.writedata().println(1).set(sub_mark[0]). } public String getName() { return stu_name.10.i<s1.thread1. s1. } public String toString() { return Rollno+".40.this.add(temp)."+sub_marks[3]+ ".50)."+sub_marks[2]+ ".get(i). } System.50). temp = new Student_Marks(1.this. s1.2630006 – Programming Skills IV (Java) sum += x. Statistical_data sd = new Statistical_data(). System.this.30.out. return sum.sub_mar ks[3].sub_marks[1]. out. synchronized(sd){} Student_Marks temp = new Student_Marks(1.out. temp = new Student_Marks(1.size(). sub_mark[2][i] = s1.getmark(0).i++) { sub_mark[0][i] = s1.%3d.printf("%3d.30. } } class Application { public static void main(String args[]) throws IOException { ArrayList<Student_Marks> s1 = new ArrayList().50).20.%3d.sub_marks[0]."Mahesg"."Suresh". sd. sd.size()]."+sub_marks[4]. } public int getRollno() { return Rollno.%3d.this.start(). s1. sub_mark[3][i] = s1.add(temp).sub_marks[4]).30.this. s1.20.getmark(3).add(temp).20.out. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 45 . PrintStream out = new PrintStream(fos)."Amit"."+sub_marks[0]+ ".i<s1.get(i)).size().getmark(4).getmark(2).%3d. %3d". sub_mark[4][i] = s1. sub_mark[1][i] = s1.this. sd.println(s1.50)."Paresh".get(i).this.getmark(1).thread1.50).sub_marks[2].println("\nDetails of sub1"). temp = new Student_Marks(1.add(temp).println()."+stu_name+".%-25S."+sub_marks[1]+ ".add(temp).20.true).get(i).10. } float sub_mark[][]= new float[5][s1.20."Anand".get(i).40. for(int i=0.txt".

sd.2f".median()).printf("\nMEDIAN %3.sd.out.out. System. System.2f".mean()).out. System.2630006 – Programming Skills IV (Java) System.2f".variance()).sd. System.sd.println("\nDetails of sub2").mean()).mean()).median()).out.printf("\nMODE %3.printf("\nMODE %3.out. System.mean()). sd.sd. System. System.2f".printf("\nMEAN %3. System.2f".variance()). System.printf("\nMODE %3.median()).printf("\nMEDIAN %3.out.out.out.sd.print("=========================================").2f".out.out.out. System.out. System.SD()).set(sub_mark[4]).out.sd.print("=========================================").printf("\nSD %3.out. System.SD()).sd.out.printf("\nMODE %3. System.2f".printf("\nVARIANCE %3.out. System.2f".print("=========================================").out.sd.variance()). System. System.printf("\nVARIANCE %3.printf("\nSD %3.out.SD()).out. System. System.printf("\nSD %3.print("========================================="). System.printf("\nMEAN %3. System.println("\nDetails of sub4").sd.set(sub_mark[1]).sd. } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 46 . System.mode()).printf("\nVARIANCE %3.2f".out.sd.sd.sd.2f".out.sd.2f".out. System.variance()).out. System. System.out.out.set(sub_mark[3]).sd. System.printf("\nMEAN %3. System.sd.SD()).2f".sd.SD()).set(sub_mark[2]).out.2f".2f".2f".sd. System.variance()). System. System.printf("\nMEDIAN %3. System. System.printf("\nMEAN %3.2f".mode()).mode()).println("\nDetails of sub5"). System.printf("\nVARIANCE %3.2f".printf("\nSD %3.out.2f".sd.mode()).out.out.2f".median()).mean()).sd.mode()). sd.2f".sd.median()).2f".print("=========================================").println("\nDetails of sub3"). sd.out. System.printf("\nVARIANCE %3.sd.printf("\nSD %3.printf("\nMEAN %3.out.2f".out.2f".sd.out.sd.2f".out.printf("\nMEDIAN %3.printf("\nMODE %3.2f".printf("\nMEDIAN %3. sd.

Dasher is a zooming interface. Dasher is an information-efficient text-entry interface.tgen. we use the predictions of a language model to determine how much of the world is devoted to each piece of text. Improbable pieces of text (for example. String str.lma. The language model learns all the time: if you use a novel word once.tit.lnm. ldesc=new Label("Desicnation:"). Checkbox male.*. lda=new Label("DA:").lgs. TextArea ta. You point where you want to go. CheckboxGroup cbg.tpf.applet.awt.lnt. and the display zooms in wherever you point.ldept.lbs. ldept=new Label("Department:").tda. To make the interface efficient. List lst. Probable pieces of text are given more space.lded. public void init() { lno=new Label("Emp No:").lda. You choose what you write by choosing where to zoom.*. lgen=new Label("Gender:"). (Hint: create a class to represent a node. import java.2630006 – Programming Skills IV (Java) 18.*. Button desp. so that any point you zoom in on corresponds to a piece of text.female. lbs=new Label("Basic Salary:").lpf.reset. Choice dept.ldesc.event.tbs. /* <applet code="prg5_26" height=1000 width=1000> </applet> */ public class prg5_26 extends Applet implements ActionListener { Label lno. TextField tno. text with spelling mistakes) are given less space.tnm. The world into which you are zooming is painted with letters. the longer the piece of text you have written. (Advanced question) import java. lnm=new Label("Emp Name:").tage.awt. Write a class in Java which models the probabilities for the alphabets in a langauge as the starting alphabet and then the probatilities for the subsequent alphabets which may follow the alphabet and so on leading to the end of word. lage=new Label("Age:").lgen.tma. so they are quick and easy to select.lit. The probabilities may be built by reading a text file containing lots of texts in the given language. so they are harder to write.tded.tgs. The more you zoom in. import java.tnt.lage. driven by natural continous pointing gestures. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 47 . it is easier to write next time. Dasher is a competitive text-entry system wherever a full-size keyboard cannot be used. which has an alphabet and its probability and each node has capability of maintaining a list of subsequent nodes).

2630006 – Programming Skills IV (Java) lma=new Label("MA:"). reset.10. lnm.20). tit=new TextField(). cbg=new CheckboxGroup().setBounds(10.setBounds(100.80.setEditable(false).80. dept. add(tnm). desp.80.70. add(female).add("pueon"). add(lnm).80. dept. add(tno). tded.addActionListener(this).70. lst.addActionListener(this). male. tgs=new TextField(). tda=new TextField(). male=new Checkbox("Male".setBounds(10.add("Dept. lst. dept.add("Executive").100. tnm=new TextField(). tage=new TextField().setBounds(100. Manager").add("Jun Executive").true).add("Manager").setEditable(false).80.add("QC").20).70.add("Marketing"). dept=new Choice(). add(lgen).add("HR"). lno.cbg.add("Assi Manager").setEditable(false).80.add("Production").20). tbs=new TextField(). setLayout(null).40. lgs=new Label("Gross Salary:").setBounds(200. lst=new List(3). add(lage). tpf=new TextField(). lage. lst. tgs. tnt=new TextField().20). dept. reset=new Button("Reset").add("Account"). lnt=new Label("Net Salary:").20). lit=new Label("IT:"). desp=new Button("Display"). lst. add(male). female=new Checkbox("Female". tnt.setBounds(100.80. tno. female.setBounds(10. lgen. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 48 . lst. ta=new TextArea(). tma=new TextField(). dept.80. dept. tded=new TextField(). lst.setBounds(10. tno=new TextField().cbg.20).add("Sales"). tnm. add(lno).true).10.20). lpf=new Label("PF:"). lded=new Label("Deduction:").20).40.

80. tgs.20).60). add(tbs). tpf.80.b.80.setBounds(300.getText(). tbs.setBounds(230.setBounds(100.20). } public void actionPerformed(ActionEvent ae) { if (ae. add(tpf).setText(str). add(ldesc).setBounds(10.setBounds(100.200.290.equals("") || tda. add(lst).20).20).pf. add(tma). add(ldept).20). tded. add(ta).getSource()==desp) { if(tno. tma.setBounds(200.80. ta.20).230.equals("") || tpf. lded. lit.80.setBounds(100.100.200.gr.equals("") || tbs.80.net.getText().20).260.80.200).80.flag.setBounds(200.80. add(lpf).equals("") || tit.getText().setBounds(300. add(tded). add(reset).20).20). add(tage). add(lma).230.290.20).getText().setBounds(300. lma.20).setBounds(100. add(tda). add(lit). tit.20).getText().170.130.ma.170.da. ldept. add(lgs).80.290. lnt. add(tnt).setBounds(300. add(lnt).200.80. add(lded).equals("") tage.320.80.getText().80. lst.20).it.2630006 – Programming Skills IV (Java) tage.20).setBounds(10.200. add(dept).setBounds(100. lpf.130.20).getText().80.80. add(lbs).setBounds(130.getText().290.equals("")) { str="Please Enter all fields".80.de.230. add(lda).20).20).130.setBounds(100.setBounds(10.80.setBounds(200.setBounds(10.130. add(desp).80. lgs.80.350. ta.equals("") || tnm. lbs.20). tda.equals("") tma. Enrolment No: 145253693056 || || Name: Pandya Meet Pankajkumar 49 .350.20). } else { int a. add(tit). reset.320.20).setBounds(100. add(tgs).80. tnt. lda.230.setBounds(100. dept.20).setBounds(200.setBounds(200.80.20).260.setBounds(10. str="".80. desp.200.bs. ldesc.

getText()).getText()).flag=0.charAt(i)!=32 ) ) { throw new Exception(""). try { a=Integer.getText().getText(). } } } catch(Exception e) { str = str + "Invalid NAME.getText()).2630006 – Programming Skills IV (Java) b=0. } try { pf=Integer. \n".parseInt(tpf.getText()).bs=0.length(). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 50 . } try { da=Integer.net=0. \n". flag = 1.parseInt(tage.parseInt(tda.a=0.getText().getText(). } try { ma=Integer.charAt(i)>122 ) && (tnm.da=0.gr=0.it=0. } catch(Exception e) { str = str + "Invalid DA.charAt(i)>90 ) && (tnm. \n".getText().de=0. \n".charAt(i)<97 || tnm. } try { for(int i=0. } try { b=Integer. } catch(Exception e) { str = str + "Invalid PF. \n".parseInt(tno. } catch(Exception e) { str = str + "Invalid MA. flag = 1. flag = 1. \n".getText(). flag = 1. flag = 1.i++) { if( (tnm.i<tnm.ma=0.charAt(i)<65 || tnm. } catch(Exception e) { str = str + "Invalid N0.getText()). } catch(Exception e) { str = str + "Invalid age.parseInt(tma.pf=0. flag = 1.

str=str+"\nEmp Nm:"+tnm. ta.setText(str). str=str+"\n Basic Salary:"+tbs.getText().getText()). } if(female. net=bs+gr-de.2630006 – Programming Skills IV (Java) } try { it=Integer.parseInt(tit. } str=str+"\t age:"+tage. tded. str=str+" Net Salary:"+tnt.getText().getSelectedItem(). tbs. tda.setText("").setText(""). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 51 .getState()) { str=str+"\nGender:"+female.setText("").setText(""+de).setText(""+net).setText("").setText(""+gr).setText(""). lst.getLabel(). } catch(Exception e) { str = str + "Invalid Basic. de=it+pf. tgs. } catch(Exception e) { str = str + "Invalid IT.setText(""). flag = 1. tnm. tage.parseInt(tbs.setText("").getSelectedItem(). str=str+"\nEmp Nm:"+tnm.setText(""). } } if(ae. tpf. \n".getSource()==reset) { tno. tgs.setText(""). flag = 1.getText()). str=str+"\n desgnation:"+lst.setText(""). tnt. } try { bs=Integer.getText(). if(male. tnt. tma.getText().getLabel(). \n". } if (flag==0) { gr=da+ma. tded. str=str+"\n Department:"+dept. str="Employ no" + tno.select(0).select(0). dept.getText().setText("").getState()) { str=str+"\nGender:"+male.setText(""). tit. } ta.getText().

if (!UrlOnError) g. urlField = new TextField("Enter url ex:google. goButton. Button goButton. // In this case an URL without a ".applet.*. public class gtu_30 extends Applet implements ActionListener { TextField urlField.awt. add(goButton). // The URL that we want to display URL userUrl. import java.com" domain. import java. import java. } public void paint(Graphics g) { // Will display when correct URL are entered and when the applet starts.awt. add(urlField). public void init() { setLayout(new FlowLayout()).com").2630006 – Programming Skills IV (Java) } } } 19. // !UrlOnError means "do if UrlOnError is false".Create an applet which has a TextField to accept a URL string.addActionListener(this). goButton = new Button("Go!"). // A help message to display when a bad URL has been typed. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 52 .event.*.80).*.drawString("Type your URL and click go!".20. and displays the document of the URL string in a new browser window.*. boolean UrlOnError.net. // This varable will determine if the URL should be loaded // or if an error message should appear.addActionListener(this). urlField. import java.

// even frame targets are possible.2630006 – Programming Skills IV (Java) else { g. So we'll fix that. g. temp = "Http://" + temp.toUpperCase(). } // if it's not longer than 6 chars then it will surely miss // the "http://" part.20. // If it is still wrong then we'll show an error message too. catch (Exception e) { UrlOnError = true. getAppletContext().80). String temp = urlField.indexOf(".com domains".getText(). } // Show the user what you have done with his typed in URL urlField. UrlOnError = false. // Now it's time to transform the String to a real URL try { // This will do that. else temp = "Http://" + temp. if (!UrlOnError) // This will do so. // Now show the error message or nothing if it was right..20. // Save the data of the textfield.com URL // If the index of ".showDocument(userUrl.equals("HTTP://")) // if not then append it to it.setText(userUrl. } // You MUST try-catch this method. if (temp.100). if (temp. } } public void actionPerformed(ActionEvent act) { // Start with good hope.drawString("This Applet only allows . // If it was right of course.toString()).length() > 6) { // Then check if it starts with "http://" if (!temp.7). repaint(). // If the URL is longer than 6 characters..substring(0. userUrl = new URL(temp). } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 53 . Note that the "_blank" part can be // replaced with "_self" or "_parent" like in HTML."_blank").drawString("Malformed URL: "+userUrl. // And finally load a new browser window and show the page. // Now that the Http:// is there we'll check if it's a .com") == -1) // So we'll show an error message later UrlOnError = true.com" is -1 that means it isn't there.

rate=0. Two sub-classes called Flat and Villa. } public void setprice() { price=area*rate. All types of residences have an area (square yards) and a rate (per square yard).out. setprice().2630006 – Programming Skills IV (Java) 20. } public void display() { System.area.java public class Flat extends Residency { int mainten. 1. Residency() { area=0. In case of Flat. a Flat or a Villa. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 54 . package residence.r). An abstract class called Residency.Consider two types of residency. Also override appropriate methods from the Object class. from Residency class. and in case of Villa the price is incremented by furniture charges. the price get incremented by the maintenance charges.println("Price="+price). 2. 3. The property price of a residency is by default calculated as area * rate. } public Residency(float a. which inherit from the Residence class and override the appropriate methods. } public Flat(float a. } abstract void moveprice().rate. with appropriate methods and constructors. rate=b. Now define the following classes in a common package called “residence”. setprice(). float b) { area=a. abstract class Residency { float price. float r) { super(a. } //flat. Flat() { super().

} } //villa. moveprice(). } public Villa(float a. objf...2630006 – Programming Skills IV (Java) public void setdata(int a) { mainten=a. Flat objf=new Flat(1000. Villa() { super()...setdata(700). class Tuto_7 { public static void main(String s[]) { System. } } OUTPUT:: Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 55 ....out. // objv.price.display(). moveprice(). } } //Main file Tuto_7.. System. // Villa objv=new Villa(2000..5f). //objv..*.250.5f).0f. } public void moveprice() { price+=furnit..println(".java class Villa extends Residency { int furnit.java import residence.setdata(500).0f.").out. } public void setdata(int a) { furnit=a...650.println(""). float r) { super(a.. objf. } public void moveprice() { price+=mainten...r).display().

Villa_Q20.out.out. //import Residence. get residence list in price range.. case 2: v2."). remove residence.15000). //import Residence.equals(v2)) { System.println(" 2.Get(). Flat_Q20 f2 = new Flat_Q20()."). Appropriate class(es) implementing the Comparator interface to make comparison of Residence based on the area. f2. EXIT").println(" 3.println("Both are Equals.println("Both are Different.Get().parseInt(br.. v2. if(v1. which maintains various Residence objects in an appropriate data structure. import java. rate or price.20000.Display().Flat_Q20. System.out. int ch = Integer. if(f1. Villa_Q20 v1 = new Villa_Q20(300.println("\n"+f1).2630006 – Programming Skills IV (Java) 21.equals(f2)) { System. These class(es) may be defined in the “residence. } else { System.*.Display(). System.out. Flat"). 2.out..5000).io. System. System. A class called PropertyList as part of the “residence” package.print("\n Enter your Choice :. } break.out.println("\n"+v1). get residence list in area range. System.30000.println(" MENU ").out.out.out. System. } else { Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 56 . Villa_Q20 v2 = new Villa_Q20().println("Both are Equals.in)).readLine()).util” package. BufferedReader br = new BufferedReader(new InputStreamReader(System.println("\n 1."). Consider the above exercise and define the following: 1. while(true) { System. has methods to add residence. switch(ch) { case 1: f2. Villa").out. class Q20 { public static void main(String args[]) throws Exception { Flat_Q20 f1 = new Flat_Q20(200.").

} public double Price() { double total = getArea() * getRate() + Maint_Charges.Maint_Charges==f.rate). System.out.print("\n Enter the Maintenance Charges :.println("\n Area = "+getArea()).in)). this.println("Both are Different.out. } public int hasCode() { return 1.Rate="+getRate() +". class Flat_Q20 extends Residency_Q20 { private double Maint_Charges.println("_______________________________").2630006 – Programming Skills IV (Java) System.out. } } } } //package Residence.Get().").out.readLine()).getRate() && Name: Pandya Meet Pankajkumar 57 . Maint_Charges = Double. } public boolean equals(Object o) { Flat_Q20 f = (Flat_Q20)o.. } public String toString() { return "\nFlat(Area="+getArea()+". } public void Get() throws Exception { super.Maintanance="+Maint_Charges+".getArea() this. BufferedReader br = new BufferedReader(new InputStreamReader(System. System.Maint_Charges = Maint_Charges. } break. //import java.parseDouble(br.println("_______________________________"). return (this. double rate. case 3: System.out.Maint_Charges). System. return total.println(" Flat Information ").").io. public Flat_Q20() { Maint_Charges = 20000. } public void Display() { System.getArea()==f.Price="+Price()+")".*.exit(0). } public double getMaint_Charges() { return Maint_Charges.getRate()==f. Enrolment No: 145253693056 && this.out. System. double Maint_Charges) { super(area. } public Flat_Q20(double area.

System. rate = 3000. public Villa_Q20() { Furniture_Charges = 20000.println("\n Maintenance = "+Maint_Charges). } } //package Residence. } public double getRate() { return rate.print("\n Enter the Area :.out. //import java.out. } public void Get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System. } public double getArea() { return area.print("\n Enter the Rate :. this. abstract class Residency_Q20 { private double area. System.println("\n Price = "+Price()). rate = Double. double rate. double rate) { this. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 58 . } abstract public double Price(). class Villa_Q20 extends Residency_Q20 { private double Furniture_Charges.Furniture_Charges = Furniture_Charges. } public Villa_Q20(double area.io.parseDouble(br. private double rate.out. } public double getFurniture_Charges() { return Furniture_Charges.out. area = Double.io.rate = rate.out.println("_______________________________").area = area. } public Residency_Q20(double area. this.parseDouble(br.println("\n Rate = "+getRate()).in)). } //package Residence. abstract public void Display(). //import java. System. System.readLine()).out. System.rate).2630006 – Programming Skills IV (Java) System."). double Furniture_Charges) { super(area.*.readLine()).").*. public Residency_Q20() { area = 500.

//import java.out. System.out.println("4.Flat_Q20. //import Residence. System. System. ListIterator i = null. } public String toString() { return "\nVilla(Area="+getArea()+".println(" Villa Information "). System.out. } public boolean equals(Object o) { Villa_Q20 v = (Villa_Q20)o.in)). Remove Residence").Furniture_Charges==v.out.out.parseDouble(br.println("__________________________").Furniture_Charges). System. } public double Price() { double total = getArea() * getRate() + Furniture_Charges.println("_______________________________"). return (this.out. int ch1.").println("\n Price = "+Price()). System.io. //import Residence.println("\n Rate = "+getRate()). System.util. System.getRate() && this.println("_______________________________").println("1.out.println("__________________________"). Villa_Q20 v = new Villa_Q20().println(" Property Management ").out.readLine()).Furniture="+Furniture_Charges+".out. class PropertyList_Q21 { public static void main(String args[]) throws Exception { List <Residency_Q20> l = new ArrayList<Residency_Q20>(). return total.out.out.out. System. System.getArea() && this. BufferedReader br = new BufferedReader(new InputStreamReader(System. } public void Display() { System.println("5.println("3. Flat_Q20 f = new Flat_Q20().println("2.2630006 – Programming Skills IV (Java) public void Get() throws Exception { super.print("\n Enter Furniture Charges :.out. } } //import Residence. Residency_Q20 r = null.Price="+Price()+")".in)). System.Villa_Q20.out. System. Furniture_Charges = Double.*.getRate()==v.out. System.out. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 59 .out. Add Residence").getArea()==v.println("\n Area = "+getArea()). while(true) { System.Get(). //import java. Get Residence List in Area Range"). System. } public int hasCode() { return 2.Residency_Q20.println("\n Furniture = "+Furniture_Charges). BufferedReader br = new BufferedReader(new InputStreamReader(System.*.println("_______________________________"). Get Residence List in Price Range").Rate="+getRate() +". System. Display ALL"). ch2.

switch(ch1) { case 1: System. ch1 = Integer.add(r). r = v.print("\n Enter your Choice :."). r = f.. l. case 5: Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 60 . } break.print("\n Enter 1 for Flat && 2 for Villa :.. v.readLine()).out.print("\nEnter Minimum Area Range : ").parseDouble(br. double min = Double.out. } else { r = v.parseDouble(br.readLine()).out. } break.out. if(r. case 3: System.print("\nEnter Maximum Area Range : ").out. double max = Double. System.").parseInt(br.listIterator().Get(). f.Price()>=min && r.hasNext()) { r=(Residency_Q20)i.add(r).2630006 – Programming Skills IV (Java) System. if(ch2 == 1) { f = new Flat_Q20(). while(i. } break.out. if(r. else System.readLine()).parseInt(br. i = l.listIterator().readLine()). min = Double. max = Double.parseDouble(br.Display().print("\nEnter Minimum Price : "). ch2 = Integer..Price()<=max) r.getArea()<=max) r. case 2: System. while(i.Get().remove(r). i = l.print("\nEnter Maximum Price : ").next().print("\n Enter 1 for Flat && 2 for Villa :.readLine()). l. } break.println("No Any Residence Available. l.readLine()).out.").. else System.parseDouble(br. System.remove(r).out. } else { v = new Villa_Q20(). EXIT").out.").out. System.parseInt(br. if(ch2 == 1) { r = f. case 4: System.hasNext()) { r=(Residency_Q20)i. l.getArea()>=min && r.println("No Any Residence Available.Display().next()."). ch2 = Integer.readLine()).println("6.

else if(f1.Price() > f2.hasNext()) { r = (Residency_Q20)i.*. else return 0.getArea() < f2. //import java. } } //package Residence. r.getRate() < f2. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 61 . } } } } //package Residence. //import java.Display(). Object o2) { Flat_Q20 f1 = (Flat_Q20)o1. //import Residence.util. while(i.Price() < f2. //import java. class FlatRateComparator_Q21 implements Comparator { public int compare(Object o1.getArea()) return -1.util.Flat_Q20.Price()) return -1. case 6: System.util.getRate()) return 1. if(f1.listIterator().getRate() > f2.*. //import Residence.exit(0).Price()) return 1.*. class FlatAreaComparator_Q21 implements Comparator { public int compare(Object o1.Flat_Q20.util. } } //package Residence. else if(f1. else return 0.Flat_Q20.util.next().getArea()) return 1. Flat_Q20 f2 = (Flat_Q20)o2.util. class FlatPriceComparator_Q21 implements Comparator { public int compare(Object o1. else return 0.getRate()) return -1. if(f1. else if(f1.2630006 – Programming Skills IV (Java) i = l. Object o2) { Flat_Q20 f1 = (Flat_Q20)o1. Object o2) { Flat_Q20 f1 = (Flat_Q20)o1. Flat_Q20 f2 = (Flat_Q20)o2. //import Residence. } break.getArea() > f2. if(f1. Flat_Q20 f2 = (Flat_Q20)o2.

*.i++) { fs = new FileSearch(args[i]). Use multithreading to process files in parallel.io. (A palindrome is a word which has the same spelling when read from left to right or right to left). String line="". The output should print all the occurences of palindromes in the file.i<words. FileSearch() { filename="palindrom. '\n'. } FileSearch(String file) { filename = file. words=line.equals(rev)) { System. int c=0. } } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 62 .print(ex. } } } fr. public class P22 { public static void main(String args[]) { FileSearch fs. } catch(Exception ex) { System. fs.split(" "). The end of line in the file will be marked by the newline character. BufferedReader br = new BufferedReader(fr). import java. if(words[i].toString().readLine())!=null) { c++.i++) { StringBuffer sb = new StringBuffer(words[i]). } } } class FileSearch extends Thread { String filename.words[]. while((line=br. sb = sb. for(int i=0.print("\nFile :"+filename+" Word="+words[i]+" Line="+c).length. } public void run() { try { FileReader fr = new FileReader(filename).reverse().length.i<args.out.close().start().2630006 – Programming Skills IV (Java) } 22.txt". Write a program that takes names of a text files as command line argument and searches the files for occurence of palindromes.toString()). for(int i=0. with their filename and line numbers.out. String rev = sb.

Feet to Centimeter. (Like if user selects Inches to Feet option and input value is 60 then message should be “60 inches is equal to 5 Feet”.5. add(b1).b4.toHexString()]. l2 = new Label("Output").addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int ip = Integer. which allows user to select a particular conversion from following options. t2. setLayout(new GridLayout(4.2.b3. Create an applet named “UnitConversion”.l2.b2. t2 = new TextField("0").48cm) 4. t1 = new TextField("100").setEditable(false). add(b4). add(l1).toHexString(ip). op = Integer. Decimal to Octal [Use Integer.setText(op). Button("Feet->CM").event. 3. 2. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 63 . add(l2).parseInt(t1. Button("Inches->Feet"). import java. public void init() { l1 = new Label("Input"). Button b1. Button("Dec->Octal"). public class P23 extends Applet { Label l1.2630006 – Programming Skills IV (Java) 23.(Use list) 1. } }). add(b3). t2.awt. Decimal to HexaDecimal [Use Integer. add(b2).(1 feet = 30.*. String op. add(t2). b1. Inches to Feet (1 feet = 12 inches) Once user selects particular conversion then show the converted value with proper formatted message.5)).) import java.*.awt.toOctalString()]. TextField t1. b1 b2 b3 b4 = = = = new new new new Button("Dec->Hexa"). add(t1).getText()).t2.

Create a class called Statistical Data.parseFloat(t1.parseFloat(t1.io. which has capability of maintaining data regarding multiplevariables. } }).parseInt(t1.BufferedReader.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { float inch = Float.InputStreamReader. Provide methods in the class to compute the correlation coefficient between any two variables.io. import java. float cm = feet*30. t2. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 64 . Test the class by computing the correlation coefficient between the marks of GCET and marks of 1st year MCA for students of your class.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { float feet = Float.getText()). import java. } } 24. specified in the parameter.getText()).48f. t2.setText(op).valueOf(cm)). b4.io. It should have a method to specify the variable names as String array and the method to load values from a file regarding the variables. eg. } }).getText()).2630006 – Programming Skills IV (Java) b2. float feet = inch/12.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int ip = Integer.setText(String. t2.toOctalString(ip). We consider two variables as percentage of marks in GCET exam and percentage of marks in 1st year of MCA.IOException.setText(String. op = Integer. } }). import java. b3.valueOf(feet)).

sab. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 65 . for(i=0.i++) { System. public StatisticalData() { v1name=new String("str1").cor_coef.readLine(). tb2=tb2+(v2[i]-m2)*(v2[i]-m2). m2=m2+v2[i]. } public void get() { BufferedReader br=new BufferedReader(new InputStreamReader(System.readLine().println("Error while Reading from console").i++) { v1[i]=Integer.printf("%s: ".v2name). } System. System. int i. m1=m1/5. } } catch(IOException e) { System.i<5.println().ta2=0.2630006 – Programming Skills IV (Java) class StatisticalData { int v1[]. v2=new int[5]. sb=tb2/5.v2name.out.i<5.printf("%d ". } } public void correl_coeff() { double d.println("Enter First variable name and its values: "). v2name="str2". String v1name. } System. int i.i<5.println().out.v1[i]).i++) { tatb=tatb+(v1[i]-m1)*(v2[i]-m2). for(i=0.v2[i]).printf("%d ".tb2=0. } System.parseInt(br.out. m1=m1+v1[i].sb. v1=new int[5]. for(i=0.m2=0.v2[]. v2name = br.out.i++) { v2[i]=Integer. ta2=ta2+(v1[i]-m1)*(v1[i]-m1).parseInt(br.println("Enter Second variable name and its values: ").readLine()).out. sa=ta2/5.tatb=0.m1=0.out.readLine()).i<5. v2name=new String(). System.sa.in)).printf("%s: ". for(i=0. m2=m2/5.i++) { System.out.sqrt(sa). System. } sab=tatb/4. for(i=0.v1name).out.out. sa=Math.i<5. try{ v1name = br.

How many different random samples of four accounts are possible. } } class P24 { public static void main(String args[]) { StatisticalData x=new StatisticalData(). TextArea ta. Also provide method to display all possible samples.lbill.*.sqrt(sb).event. we want to take a random sample of four accounts in order to learn about the population. (Hint use random method of the Math class to select the random sample).b2.pre.ttax.tbill.out.correl_coeff(). public void init() { lno = new Label("Cell Number"). import java.*. derived from the possible samples. import java.awt.lsec.*. and also a method to return a sample.tsms. Choice cst.get().lsms.println("correlation co-efficient: " + cor_coef).applet. System. import java. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 66 . Simple random sampling uses a sample of size n from a population fo size N to obtain data that can be used to make inferences about the characteristics of a population. /* <applet code="prg5_25" width = 500 height=500> </applet> */ public class prg5_25 extends Applet implements ActionListener { Label lno.Write a Java class which can compute the number of random samples for size n from a population of N.awt.lnm.gps.lst.lplan.tmin.2630006 – Programming Skills IV (Java) sb=Math.ltax. lnm = new Label("Customer Name").iwrld. from a population of 50 bank accounts.lmin. Checkbox gen. Suppose that. cor_coef=sab/sa*sb.lhr.thr.lcall.lext. Checkbox gprs. x. x. } } 25.tnm.tsec. CheckboxGroup cbg. TextField tno. Button b1.

thr. lplan.100.100.40. gen = new Checkbox("General".setBounds(110.setBounds(10.50. tnm = new TextField(). lmin = new Label("Miniute"). tnm. cst = new Choice().100.add("MP"). tmin. cbg = new CheckboxGroup().cbg. thr = new TextField(). lnm. add(lcall).20).setBounds(110.setEditable(false).20). add(tmin).setBounds(110. tmin = new TextField(). add(lhr). cst.setBounds(260. add(lplan). lbill = new Label("Bill Amount"). cst.true). gprs = new Checkbox("GPRS"). b2.50.setBounds(10. tno.130.20). add(cst).20).150.addActionListener(this).20). ta = new TextArea().false).130.40. tbill = new TextField().setBounds(250.20).100. lsms = new Label("Total SMS").add("AP"). lhr. add(lst). lplan = new Label("Bill Plan").add("Goa"). add(lnm). cst. lext = new Label("Extra Facilities").50. add(thr).130. add(lsms). add(tno). lmin.20).100. tsms = new TextField().100. pre = new Checkbox("Premium".20).70. cst.setBounds(160.20). ttax = new TextField().20). add(tnm). b2 = new Button("Reset"). gen. add(gen).50. tno = new TextField(). tbill.add("UP").20). lcall. cst.10. lhr = new Label("Hours").70.100.100.10.setBounds(10. add(lmin).130.cbg. b1.50. setLayout(null). cst. add(tsms).setBounds(210.setBounds(110.20). lst. ltax = new Label("Tax").10. pre.setBounds(330. gps = new Checkbox("GPS"). add(lno). lcall = new Label("Total Call"). lsms.100. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 67 . tsms.20).2630006 – Programming Skills IV (Java) lst = new Label("State").20).addActionListener(this). cst. add(pre).100.70. tsec = new TextField().setBounds(10.20).add("JK").setBounds(10.100.130. iwrld = new Checkbox("i-World").80. lno.add("Gujarat"). lsec = new Label("Second").setBounds(110.setBounds(210. b1 = new Button("Display").20).10.

add(tbill).equals("") ||tmin. lsec. gps.130.80. add(ltax).flag. } catch(Exception e) { msg = msg+"Invalid SMS Value\n".hr.190. flag = 1.mn.250.100.280.getText()).getText().100. add(gps).80. cell = 0.20). iwrld. hr = 0.20).getText().tx. int cell. sc = 0. if( ae.20).400. tbill.equals("") ||ttax. ta.20).setBounds(10.sms.20).equals("") ||tnm.getSource()==b1 ) { if( tno. } else { try { cell = Integer.setBounds(360.setBounds(310.160. } try { sms = Integer.setBounds(50.equals("") ||tsec.80.getText(). } catch(Exception e) { msg = msg+"Invalid Cell Number\n".equals("") ) { ta.50. add(gprs).setText("Enter Values for each field\n"). gprs.equals("") ||thr. add(ttax).100. mn = 0. sms = 0. add(b1).setBounds(190. add(lext). add(tsec).220.getText().setBounds(10.2630006 – Programming Skills IV (Java) tsec.20).setBounds(110. msg = "". flag = 0.50.200). b2.100.setBounds(170.setBounds(10. ttax.setBounds(110.setBounds(270.130. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 68 .190.equals("") || tsms.sc. ltax. add(lbill). b1.220.20). add(b2). add(ta).setBounds(10.getText()).250.setBounds(110.20). lext.20).100.getText(). add(iwrld).20).100. add(lsec).190. lbill.20).getText().190.parseInt(tno. tx = 0.20).parseInt(tsms. } public void actionPerformed(ActionEvent ae) { String msg.160.getText().50.

callrs = 0. callps = 0. flag = 1. mn = mn*1.parseInt(ttax.getText()). } catch(Exception e) { msg = msg+"Invalid Second Value\n". callmn = hr+mn+scnd.smsps. hr = hr*60.smsrs. amt = 0.callrs. if( gen. msg = msg + "State : "+cst. } try { sc = Integer.callmn.parseInt(tsec.parseInt(thr. scnd = (double) sc/60. iwrldrs = 0. flag = 1. msg = msg + "Customer Name : "+tnm.parseInt(tmin.getSelectedItem()+"\n". } try { hr = Integer. smsrs = 0. msg = msg + "\nBilling Plan : ".2630006 – Programming Skills IV (Java) flag = 1. smsps = 0.prers.getLabel(). callps.genrs.getText()+"\n". } catch(Exception e) { msg = msg+"Invalid Hour Value\n". flag = 1. genrs = 0.scnd. gpsrs = 0. } if( flag==0 ) { double amt. } catch(Exception e) { msg = msg+"Invalid Miniue Value\n". } try { tx = Integer. gprsrs = 0.gprsrs. flag = 1. prers = 0. msg = msg + gen.gpsrs.taxrs.getText()+"\n". } try { mn = Integer.getText()).iwrldrs.getText()).getState() ) { genrs = 200. msg = "Cell Number : "+tno. if( sms<100 ) Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 69 . prers = 0.getText()). } catch(Exception e) { msg = msg+"Invalid Tax Value\n".

} else { callps = (callmn-500)*0. msg = msg + gps. } amt = genrs + prers + smsrs + callrs + taxrs + gprsrs+ gpsrs + iwrldrs. } if( iwrld.getLabel().setText(msg).05.getLabel()+".3. msg = msg + "\n\n".1. } else { smsps = (sms-100)*0.getState() ) { genrs = 0. msg = msg + iwrld. } ta.getState() ) { gpsrs = 200.getState() ) { gprsrs = 100. } } if( pre.getLabel()+". if( gprs. msg = msg + "\n\n". ".". prers = 500. tbill. msg = msg + pre.2630006 – Programming Skills IV (Java) { smsps = 0. callrs = callps/100. ". } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 70 . } } smsrs = smsps/100. } if( gps. msg = msg + "Extra Facility : ". if( sms<500 ) { smsps = 0.setText(""+amt). } if( callmn<1000 ) { callps = 0.getState() ) { iwrldrs = 150.5. msg = msg + "Bill Amount : " + amt. } else { smsps = (sms-100)*0.getLabel()+". taxrs = (double) tx. } else { callps = (callmn-500)*0. msg = msg + gprs. } if( callmn<500 ) { callps = 0.

io. } else if(n>=11 && n<20) { System. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 71 .print(l1. public P28() { try { init(). int d2 = n%10. tmin.2630006 – Programming Skills IV (Java) if( ae..out. thr.get(0)). tnm.get(d1)). // 100.get(d3)+" "+l4.setText("").out.get(d3)+" "+l4. n = n/10. int n. public class P28 { BufferedReader br = new BufferedReader(new InputStreamReader(System.out. System.setText(""). // 20 to 90.Write an application to convert digits into words.out. // 11 to 19. ttax.print(l1.get(d1)). System.setText("").readLine()). else System.getSource()==b2 ) { tno.out. 1000. n = Integer. else if(d2==0) System.print(l1.print(l1.out. tsec. System.get(d1)).setText(""). 10000.print("").get(n)).*.out. n = n/10.get(0)+" "+l3.print(l3. List <String> l2. } else if(n>20 && n<100) { int d1 = n%10.get(d2-2)+" "+l1.print(l2. n = n/10.setText("").in)).out..print("").setText("").print("\nEnter Number : "). import java.get(0)+l1. tsms. import java. List <String> l3. System. List <String> l1. int d3 = n%10. } else if(n>=100 && n<1000) { int d1 = n%10.*.get(d2-2)+" "+l1. List <String> l4. } } } 28. tbill.out.parseInt(br. int d2 = n%10. use appropriate structures available from java. if(d1==0 && d2==0) System.util package.setText("").. // 0 to 9. if(n>=0 && n<10) { System.util.get(d3)+" "+l4.setText("").get(n-11)).

add("seventeen").add("sixty"). l2.add("fourteeh").add("eighty").add("ninety").add("nine").add("fifty"). l4.add("seventy"). l3. l4 = new ArrayList<String>(). l1.add("fifteen").add("thirty").add("eighteen").add("two"). l2.add("fourty"). l3. l1. l3.add("therteen").add("hundreds").add("lakhs"). l1.out.add("zero").add("eleven"). l2.2630006 – Programming Skills IV (Java) } } catch(Exception ex) { System.add("three"). l4.add("thousands"). l1.add("one"). l2.add("tweleve"). } } public void init() { l1 = new ArrayList<String>(). } public static void main(String args[]) { new P28(). l1.add("crores"). l1.add("nineteen"). l3. l1. l2.add("twenty").add("four"). l4.add("five").add("sixteen"). l2. l3. l3.add("seven"). l2. l3 = new ArrayList<String>(). l1.add("six").print(ex). } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 72 .add("eight"). l2 = new ArrayList<String>(). l4. l1. l2. l3. l2. l1. l3.

out.parseInt(br. which in turn has teacher (subject. Typist").print("\nStaff Registration").print("\n3.print("\n2.in)). name) is the base class. Teacher").get(). Done").print("\n2.out.print("\n4 Quit").dataWriter().out.readLine()).out.readLine()).print("Enter choice : ").out. } case 3 : { int ch4. The typist again has regular ( ) and causal (daily Wages) as its child classes. publication).print("\n2.print("\nEnter choice : ").out. System.out.out. Note that the information given in brackets specifies the minimum information required for each class.out.dataWriter().get().out.parseInt(br. System. System. System.dataWriter(). break. typist (speed) and officer (grade) as its child classes. System. t. o. t.print("\n3. Officer"). Regular").print("\nStaff Registration").print("\n3. System.out. Quit").print("\n1. An educational institution wishes to maintain a database of its employees. o. } case 2 : { Officer o = new Officer(). if(ch4 == 1) { Regular r = new Regular(). import java. do { System. Staff Details").print("1.out.readLine()). System. class P29 { public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.2630006 – Programming Skills IV (Java) 29. The database is divided into a number of classes whose hierarchical relationships are as follows: ◦ Staff (code. break. System. while (true) { System. switch(ch2) { case 1 : { Teacher t = new Teacher().print("\n==============="). r.out.io. if(ch1==1) { while(true) { System. System.out.get(). System. Staff Registration"). System.print("\nEnter choice : "). r.out.parseInt(br.out.out.*. Casual").print("\n1. Specify all classes and define functions to create the database and retrieve information as and when needed. System. ch4 = Integer.print("\n==============="). System. int ch2 = Integer. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 73 . System. int ch1=Integer.

c.print("\n3.readLine()).dataReader().out. System.dataWriter(). Done"). c. Teacher"). } case 2 : { Officer o = new Officer(). t.out.print("Invalid Choice!!!.out.print("\n===============").out. } else { System.exit(1). else if(ch1==2) { while(true) { System.parseInt(br. System.. System.print("\nEnter choice : "). } case 4: { System. switch(ch3) { case 1 : { Teacher t = new Teacher(). Casual").out.print("\n==============="). } else if(ch5 == 2) { Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 74 . System. Regular")..dataReader(). System.print("\n2. System.print("\nEnter choice : "). break. System.print("\n4 Quit"). int ch3 = Integer. o. break.print("\n1. r. System.out. break.dataReader(). System.out.parseInt(br. } }while(ch4 >0 && ch4 <3).print("\n2.readLine()). ch5 = Integer.out.print("\nStaff Details"). System. if(ch5 == 1) { Regular r = new Regular().out.print("\n3. do { System.print("\n1. } case 3 : { int ch5.out. Officer").2630006 – Programming Skills IV (Java) } else if(ch4 == 2) { Casual c = new Casual(). Typist").out.get().").print("\nStaff Registration").out. System. } }//switch case }//inner while }//end of if.out...out.

System.speed).print("\n Employee Code : " + getCode()).String name.out. System..io.int speed. } }//outer while loop } } //import java.in)).out.").get(). fw.out.readLine()). System.print("\n Enter wages : "). fw. } public void display() { System. System. wages=s.*.double s) { super(code.out.write(str .print("\n Employee Name : " + getName()).. public Regular() { wages=100.name. 0 . } public void dataWriter() { try { String str = new String(getCode() + " | " + getName() + " | " + getSpeed() +" | "+ wages + "\n").print("\n Typing Speed : " + getSpeed()).print("\n Regular wages : " + wages). } case 4: { System.2630006 – Programming Skills IV (Java) Casual c = new Casual().close(). FileWriter fw = new FileWriter("regular. } public void get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System. } else { System. } public Regular(int code. class Regular extends Typist { double wages. fw.exit(1).length()). c. wages=Double. break.parseDouble(br.txt".true).out.write(13). } }//switch case }//inner while }//end of else if else { System. fw. } }while(ch5 >0 && ch5 <3).write(10). } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 75 .dataReader().print("Invalid Choice!!!.out. super.exit(1). str.

txt". } } } //import java.String name. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 76 . public Casual() { salary=100.int speed.*. salary=Double.readLine()) != null) { System.write(str .print("\n Enter Salary : "). fw. System.readLine()).write(13).print(str + "\n"). } public void display() { System. while((str=br.write(10).speed).out. FileWriter fw = new FileWriter("casual.out. salary=s. super. } catch(Exception e) { System.true). System. System.parseDouble(br. } } public void dataReader() { try { FileReader fr = new FileReader("regular.in)). 0 .close(). // fetches line by line from file String str = new String().txt").out.print("\n Typing Speed : " + getSpeed()).2630006 – Programming Skills IV (Java) catch(Exception e) { System. System. class Casual extends Typist { double salary.out.get(). fw. } public void get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System. fw. } fr.out.print("\n Casual Salary : " + salary). } public void dataWriter() { try { String str = new String(getCode() + " | " + getName() + " | " + getSpeed() +" | "+ salary + "\n").print("\n Employee Code : " + getCode()).close().out.out.length()). fw.getMessage()). } public Casual(int code.print(e.print("\n\n\t\t\t " + e.out.print("\n Employee Name : " + getName()).double s) { super(code. str.io. BufferedReader br = new BufferedReader(fr).getMessage()).name.

0 .print("\n\n Employee Name : " + getName()).char s) { super(code. // fetches line by line from file String str = new String(). } } public void dataReader() { try { FileReader fr = new FileReader("casual. } public char getgrade() { return grade. FileWriter fw = new FileWriter("officer.out.out.out. grade=s. grade=br. } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 77 . public Officer() { grade='A'.2630006 – Programming Skills IV (Java) catch(Exception e) { System.in)). System. System. while((str=br. fw.length()). System.charAt(0).readLine().readLine()) != null) { System.out.print("\n\n Officer grade : " + grade). } } } //import java.out. } public void dataWriter() { try { String str = new String(getCode() + " | " + getName() + " | " + grade + "\n").print("\n\n Employee Code : " + getCode()).println("\n\n Enter Grade : ").String name.write(str . fw. super.get().print(str + "\n").txt". } fr.write(10).getMessage()).out.write(13). } public void get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System. class Officer extends Staff { char grade.getMessage()). BufferedReader br = new BufferedReader(fr).print(e.close().name).txt").out. fw. } public Officer(int code.print("\n\n\t\t\t " + e.true).close(). } public void display() { System.*.io. str. } catch(Exception e) { System. fw.

readLine()). } fr.io. System.out.parseInt(br. public Teacher() Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 78 . nm = new String(""). class Teacher extends Staff { private String sub.print(str + "\n").io. public abstract void dataWriter().getMessage()).println("\n\n Enter Employee code : ").*. System.out. BufferedReader br = new BufferedReader(fr).out.2630006 – Programming Skills IV (Java) catch(Exception e) { System. } public int getCode() { return code.close(). } } } //import java.println("\n\n Enter Employee Name : ").String name) { code = no. public abstract void dataReader().readLine()) != null) { System. while((str=br. code=Integer. } public abstract void display(). } } public void dataReader() { try { FileReader fr = new FileReader("officer.out.getMessage()).pub. } catch(Exception e) { System. nm=br. } public void get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.print(e. abstract class Staff { private int code. nm = name.*. private String nm.print("\n\n\t\t\t " + e.txt"). } //import java. } public String getName() { return nm.readLine().out. } public Staff(int no. public Staff() { code = 0. // fetches line by line from file String str = new String().in)).

readLine().readLine().io.print("\n\n\t\t\t " + e.out.true). fw. } public void get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System. } public void dataWriter() { try { String str = new String(getCode() + " | " + getName() + " | " + sub + " | " + pub + "\n").write(10).write(13). class Typist extends Staff { int speed.out.close().txt".print("\n\n Publication : " + pub).name).String nm) { super(code. System.String name. fw.close(). } catch(Exception e) { System. } fr. BufferedReader br = new BufferedReader(fr). } public Teacher(int code.out. sub=br.length()).out.out. FileWriter fw = new FileWriter("teacher. } } public void dataReader() { try { FileReader fr = new FileReader("teacher.2630006 – Programming Skills IV (Java) { sub=pub="". pub=br. } public void display() { System.print(str + "\n"). fw.*. System. } catch(Exception e) { System.getMessage()). str.out.readLine()) != null) { System. sub = no.print("\n\n Employee Name : " + getName()).out. System. pub = nm. while((str=br.in)).out.out.get(). System.String no.txt").println("\n\n Enter Subject name : ").print("\n\n Employee Code : " + getCode()). // fetches line by line from file String str = new String().getMessage()).print("\n\n Subject : " + sub). public Typist() Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 79 . } } } //import java. System.println("\n\n Enter Publication Name : "). fw.print(e. super.write(str . 0 .

speed=Integer. shape. and a Rectangle as two points on diagonally opposite corners. Circle and Rectangle. System.name). Now define a class called DrawingBoard.int s) { super(code. also oerrides the paint method to draw the Shape instances maintained in the List.readLine()). You can represent – a line as two points. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 80 . Derive subclasses for Point.parseInt(br.2630006 – Programming Skills IV (Java) { speed=10. speed=s. } public void get() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System. } public Typist(int code. a circle as a centerPoint and a radius.String name. which is passed as parameter.println("\n Enter Typing Speed : "). Line.get(). and a public abstract method paint() to draw the shape on a Graphics object. } public int getSpeed() { return speed. which extends the Canvas class and maintains instances of the Shape objects in a List. super. a public abstract method to compute the area of the shape.out. } public void display() {} public void dataWriter() { } public void dataReader() { } } 30.in)).

import java.y).int y) { this.*. } public double area() { return Math. } public abstract double area().y).x1. import java. this.drawLine(x.*. y=0.applet. } Shape(int x.y=y. abstract class Shape { int x.0.PI*r*r.y1=y1. } class Line extends Shape { int x1. this.awt. public abstract void paint(Graphics g).x1=x1.r=r.2630006 – Programming Skills IV (Java) /* <applet code="P30" width=800 height=600></applet> */ import java. } } class Circle extends Shape { int r.int y1) { super(x.int x1. } public double area() { return 0.y1). Circle() { x=100. } public void paint(Graphics g) { Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 81 .y1. r=100.*. y=100. this.int y.event.y.awt. this. Shape() { x=0. Line() { } Line(int x. } Circle(int x.x=x. } public void paint(Graphics g) { g.int y.int r) { super(x.y.

y-r/2.100. } public void paint(Graphics g) { g.50).drawString("Area of Rectangle is "+String. r. Rectangle r.valueOf(a1). } } public class P30 extends Applet { Line l.100.y.x1=x1.paint(g).y1. } public void paint(Graphics g) { l.paint(g).drawOval(x-r/2.200.350.y). this.int x1. a2 = r. Circle c.y1).int y. c = new Circle(100.paint(g).x1. double a1. g. } public double area() { return x1*y1.100).valueOf(a2).r). Rectangle() { } Rectangle(int x.75).300.r.a2.200. public void init() { l = new Line(100.int y1) { super(x.2630006 – Programming Skills IV (Java) g. this. } } class Rectangle extends Shape { int x1. g. } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 82 .100). a1 = c.100.y1=y1.300).area().area().drawRect(x. r = new Rectangle(200.drawString("Area of Circle is "+String. c.

address and age of the student. 3. The class should also contain appropriate get and set methods. 1. 3. The frame should also have two buttons with the caption as “Add Record” and “Search Record”. A class named AddStudentFrame which displays a frame consisting of appropriate controls to enter the details of a student and store these details in the Student class object.1. The “Search record” button should open a new frame which should take input of search criteria using a radio button. A class named Student which stores information like the roll number. the user should be asked to input the complete path of the file where he desires to save the records. [The records should be searched from the pre – defined file which consists all saved records][Note: Use the MyCustomListener class only to handle the appropriate events] Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 83 . The new frame should also have a text box to input the search criteria value. last name. 2. first name. middle name. When the “Set the record file” menu item is clicked. C. 2.[Note: Use the MyCustomListener class only to handle the appropriate events] D. “Set the record file” and “Exit”. The radio button should provide facility to search on basis of first name.The “Add record” button should add the record entered in the frame controls to a pre – defined file.2630006 – Programming Skills IV (Java) List-2 1. A class named MyCustomListener which should work as a user – defined event listener to handle required events as mentioned in following points. The search result should be displayed in a proper format on the same frame in a text area.Write a JAVA program which performs the following listed operations: A. the frame should be closed. When the “Exit” menu item is clicked. middle name or last name.Create a package named MyPackage which consists of following classes 1. 2.Provide a menu on the AddStudentFrame which has menu items titled. B.

TextField tffirst.addActionListener(this).*. Label lbllast.addActionListener(this). Student st. b1. add(lblroll).add (a). lblfirst = new Label("First Name"). MenuItem a1 = new MenuItem("Exit"). MenuItem c1 = new MenuItem("Red"). tflast = new TextField(30). a. lblmsg = new Label(" "). add(lblmsg). c1. b1 = new Button("Search"). MenuBar mb = new MenuBar(). Menu a = new Menu("File"). mb.awt. mb. TextField tfroll.awt.add (b). b. add(lblstatus).add(c1). tfroll = new TextField(30). add(tfroll). import java. Label lblmsg.io. b. Button b. Label lblfirst.add(a1).addActionListener(this). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 84 . public AddStudentFrame() { st = new Student().b1. Menu b = new Menu("Color"). add(tffirst).Provide proper error messages and perform appropriate exceptions where ever required in all the classes package MyPackage. Label lblstatus. import java.*. setMenuBar(mb).event. WindowListener { Label lblroll. import java. b = new Button("Save"). lbllast = new Label("Last Name"). add(tflast). public class AddStudentFrame extends Frame implements ActionListener. TextField tflast. setLayout(new FlowLayout()). add(lbllast). add(b). //import MyPackage. a1. tffirst = new TextField(30).*. add(b1). lblroll = new Label("Roll No: ").*.addActionListener(this). lblstatus = new Label(" "). add(lblfirst).2630006 – Programming Skills IV (Java) E.

setdata(str..getname()).getname().add(c2). //fullname = st. } public void windowActivated(WindowEvent we) {} public void windowDeactivated(WindowEvent we) {} public void windowClosing(WindowEvent we) {} public void windowDeiconified(WindowEvent we) {} public void windowIconified(WindowEvent we) {} public void windowOpened(WindowEvent we) {} public void windowClosed(WindowEvent we) {} public void actionPerformed(ActionEvent evt) { String str = evt. }catch(Exception e) { lblmsg.setText("Record Not Found !").addActionListener(this). tflast.addActionListener(this).st. setSize(360. } } else if(str.getText()). else lblmsg. c2.exit(0). " + fullname).setstudent(r. c3.setText("Sorry.equals("Red")) { //setColor(Color. MyCustomListener m = new MyCustomListener().add(c3). } else if(str. "".getText(). Record Not Saved !").getText()). lblmsg. MyCustomListener m = new MyCustomListener().parseInt(tfroll. }catch(Exception e) { lblmsg. if(str. MenuItem c3 = new MenuItem("Blue"). if (fullname == "Not Found") lblmsg. setTitle("Welcome tO Program 1 About Student Management").equals("Save")) { try { int r = Integer.tfroll. st. b. "Baroda").getMessage()).setText(e.Red). b. } } else if (str. m.getActionCommand().. tffirst.getdata(str. } } public static void main(String[] args) { AddStudentFrame t = new AddStudentFrame(). ").2630006 – Programming Skills IV (Java) MenuItem c2 = new MenuItem("Green"). } } class Student Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 85 .equals("Exit")) { System.equals("Search")) { try { String fullname.setText("Record Saved.getText().setText("Welcome. setVisible(true). fullname = m. 420).

String ln. } public void setstudent(int r. String middle_name. last_name=ln. } } class MyCustomListener { MyCustomListener() {} public void setdata(String str. String ad) { try { roll=r.printStackTrace(). } catch (IOException e) { e. String address. String last_name. fw. FileWriter fw = new FileWriter(f).getMessage()). String mn. address=ad.write(commaSeparated)." + first_name + ".String val) { String t. middle_name="". String first_name.txt").""). middle_name=mn. address="".out.close(). } File f = new File("f1. int age. String fn. first_name="". } else { commaSeparated = commaSeparated + val.String val) { if(str. Student() { roll=0.equals("Save")) { try { String commaSeparated = getdata("All".length() > 0 ) { commaSeparated = commaSeparated + ". fw. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 86 . }catch(Exception e) { System." + val.2630006 – Programming Skills IV (Java) { int roll.println(e. first_name=fn. last_name="". } } public String getname() { return(roll +". if ( commaSeparated. } } } public static String getdata(String str." + last_name).

} } return "Not Found".equals(val) ) { return items[j+1] + " " + items[j+2]. int i. } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 87 . } fr. j < items. if(str. }catch(Exception e) { } } else if(str.. while ( (i = fr. } fr. Record Not Saved !"). String [] items = t.read() ) != -1 ) { t = t + (char)i. FileReader fr = new FileReader(f). } } }catch(Exception e) { //lblmsg.close().").split(".close().equals("Search")) { try { File f = new File("f1.read() ) != -1 ) { t = t + (char)i.equals("All")) { try { File f = new File("f1. FileReader fr = new FileReader(f).length. for (int j = 0. while ( (i = fr. return t.txt"). return "Not Found".2630006 – Programming Skills IV (Java) t = "". j++) { if( items[j].txt").setText("Sorry. int i.

TextField tfpassm.*. When the “Set the record file” menu item is clicked.*.awt. 3. “Set the record file” and “Exit”. Button b. the user should be asked to input the complete path of the file where he desires to save the records. C Provide a menu on the AddCourseFrame which has menu items titled. Label lblcurnm. Max_Marks.io.awt.2630006 – Programming Skills IV (Java) 12. WindowListener { Label lblcurno. TextField tfcurno. Course name. The class should also contain appropriate get and set methods.*.Write a JAVA program which performs the following listed operations: A. 2. When the “Exit” menu item is clicked. Label lblmsg. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 88 . 3. the frame should be closed. Label lblmaxm. The new frame should also have a text box to input the search criteria value. TextField tfmaxm. import java. The “Search record” button should open a new frame which should take input of search criteria using a radio button. 2. The radio button should provide facility to search on basis of course name. import java.b1. import java. A class named MyCustomListener which should work as a user – defined event listener to handle required events as mentioned in following points. The frame should also have two buttons with the caption as “Add Record” and “Search Record”. 1.Provide proper error messages and perform appropriate exceptions where ever required in all the classes package MyPackage. [Note: Use the MyCustomListener class only to handle the appropriate events] D-1. Student st.Create a package named MyPackage which consists of following classes 1. public class AddCourseFrame extends Frame implements ActionListener. TextField tfcurnm. 2. Label lblpassm. The search result should be displayed in a proper format on the same frame in a text area. B The “Add record” button should add the record entered in the frame controls to a pre – defined file. A class named AddCourseFrame which displays a frame consisting of appropriate controls to enter the details of a Course and store these details in the Course class object. [The records should be searched from the pre – defined file which consists all saved records][Note: Use the MyCustomListener class only to handle the appropriate events] E. Pass_Marks. A class named Course which stores information like the Course no. //import MyPackage.*.event.

add(lblmsg). tfmaxm = new TextField(30). lblcurnm = new Label("Course Name").add (a). Menu a = new Menu("Set Record File"). add(lblcurnm). Menu b = new Menu("Exit"). } public public public public public public void void void void void void windowActivated(WindowEvent we) {} windowDeactivated(WindowEvent we) {} windowClosing(WindowEvent we) {} windowDeiconified(WindowEvent we) {} windowIconified(WindowEvent we) {} windowOpened(WindowEvent we) {} public void windowClosed(WindowEvent we) {} public void actionPerformed(ActionEvent evt) { String str = evt. MenuBar mb = new MenuBar(). mb.add(a1). add(b1). lblcurno = new Label("Course No: "). add(lblmaxm). a1.getActionCommand(). b. add(tfcurno). b1 = new Button("Search").add (b). add(lblpassm).2630006 – Programming Skills IV (Java) Label lblstatus. MenuItem a1 = new MenuItem("Exit"). lblmaxm = new Label("Max Marks"). add(lblstatus). b = new Button("Save"). setVisible(true). tfcurno = new TextField(30). lblmsg = new Label(" "). setLayout(new FlowLayout()). lblpassm = new Label("Pass Marks"). b1. b. setTitle("Welcome tO Program 1 About Student Management"). add(lblcurno).addActionListener(this). tfpassm = new TextField(30). tfcurnm = new TextField(30). add(tfmaxm).addActionListener(this). setMenuBar(mb). a.addActionListener(this). public AddCourseFrame() { st = new Student(). add(b). lblstatus = new Label(“ ").addActionListener(this). mb.equals("Save")) { try { Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 89 . add(tfpassm). 420). if(str. add(tfcurnm). setSize(360.

int maxm. //fullname = st. m. Record Not Saved !").setText("Record Not Found !").mm.Red). passm=0.setText("Record Saved. MyCustomListener m = new MyCustomListener(). " + fullname). int pm = Integer.exit(0).getText()).parseInt(tfmaxm. } else if(str.setstudent(r. maxm=mm.setText(e. else lblmsg.getMessage()).equals("Search")) { try { String fullname. } public void setstudent(int r.getText().parseInt(tfcurno. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 90 .setText("Sorry.equals("Red")) { //setColor(Color. Student() { curno=0. } } class Student { int curno. }catch(Exception e) { lblmsg..tfcurnm. int pm) { try { curno=r. String cn.pm). maxm=0.getdata(str.getText()).getText()). } } public static void main(String[] args) { AddCourseFrame t = new AddCourseFrame(). int mm = Integer.equals("Exit")) { System.parseInt(tfpassm. if (fullname == "Not Found") lblmsg. int mm. fullname = m. cur_name=cn.setText("Welcome. MyCustomListener m = new MyCustomListener(). "). st.2630006 – Programming Skills IV (Java) int r = Integer. } } else if(str.setdata(str. String cur_name. int passm. cur_name="".getname(). }catch(Exception e) { lblmsg. lblmsg..getText()). } } else if (str.st.tfcurno.getname()).

read() ) != -1 ) { t = t + (char)i. //Code to Save Data to File } catch (IOException e) { e.2630006 – Programming Skills IV (Java) passm=pm. fw. } } public String getname() { return(curno +".getMessage()). FileWriter fw = new FileWriter(f).close(). }catch(Exception e) { System. int i.txt").out. } } } public static String getdata(String str. FileReader fr = new FileReader(f).""). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 91 .txt"). t = "". if ( commaSeparated." + cur_name + ".println(e.close().length() > 0 ) { commaSeparated = commaSeparated + ". } File f = new File("cur. if(str.String val) { String t." + passm). fw. } fr. } else { commaSeparated = commaSeparated + val." + maxm + "." + val.equals("Save")) { try { String commaSeparated = getdata("All".write(commaSeparated). } } class MyCustomListener { MyCustomListener() { } public void setdata(String str.String val) { if(str.printStackTrace().equals("All")) { try { File f = new File("cur. while ( (i = fr.

close().equals(val) ) { return items[j+1] + " " + items[j+2]. The “Delete Record” button should open a new frame which should take input of delete criteria using a radio button. When the “Exit” button is clicked. j++) { if( items[j].read() ) != -1 ) { t = t + (char)i."). FileReader fr = new FileReader(f). } } 25. int i. the frame should be closed. } fr. Price.split(". B-1. Boat Color. 2. the dialog box should be appeared with asking the user “Do you really want to add record in the file”. 3. A class named MyCustomListener which should work as a user – defined event listener to handle required events as mentioned in following points. String [] items = t. The radio button should provide facility to delete on basis of Boat Name. } } }catch(Exception e) { return "Not Found". Boat Name. A class named Boat which stores information like Boat Id.equals("Search")) { try { File f = new File("cur. If the user selects Yes than the record should be saved in the file. } } return "Not Found".txt"). while ( (i = fr. 2. The class should also contain appropriate get and set methods.Write a JAVA program which performs the following listed operations: A. for (int j = 0.2630006 – Programming Skills IV (Java) return t. j < items. A class named AddBoatFrame which displays a frame consisting of appropriate controls to enter the details of a Boat and store these details in the Boat class object. Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 92 .Create a package named MyPackage which consists of following classes 1. }catch(Exception e) { } } else if(str. The frame should also have three buttons with the caption as “Add Record” and “Delete Record” and “Exit”.length. [Note: Use the MyCustomListener class only to handle the appropriate events] C-1. When the “Add Record” button is clicked.

addActionListener(this). tfbclr = new TextField(30).awt. import java. TextField tfbid. public AddBoatFrame() { st = new Student(). lblbprice = new Label("Boat Price"). setLayout(new FlowLayout()). add(tfbid). lblmsg = new Label(" "). add(b). public class AddBoatFrame extends Frame implements ActionListener.event. tfbprice = new TextField(30). add(lblbid). tfbnm = new TextField(30).[Note: Use the MyCustomListener class only to handle the appropriate events] D.awt. b1 = new Button("Delete"). TextField tfbprice. The record should be deleted from the file and a message dialog should appear with the message that “Record is successfully deleted”. lblbnm = new Label("Boat Name"). add(tfbclr). Label lblbnm.addActionListener(this). Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 93 . add(lblbprice). lblbclr = new Label("Boat Color").io.*. Label lblbprice. add(b2). TextField tfbclr. Label lblstatus. Button b. b = new Button("Save"). add(b1). import java. TextField tfbnm. WindowListener { Label lblbid.b1. add(tfbprice). Student st. add(lblbnm). b1. b.*. b2 = new Button("Exit"). add(lblmsg). add(tfbnm). b2.*.Provide proper error messages and perform appropriate exceptions where ever required in all the classes package MyPackage. tfbid = new TextField(30).addActionListener(this). Label lblbclr. The new frame should also have a text box to input the delete criteria value.2630006 – Programming Skills IV (Java) 2. lblbid = new Label("Boat Id: ").b2. import java. 3. add(lblbclr). Label lblmsg.

2630006 – Programming Skills IV (Java)
lblstatus = new Label(“
add(lblstatus);

");

MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu a = new Menu("");
mb.add (a);
MenuItem a1 = new MenuItem("");
a1.addActionListener(this);
a.add(a1);
Menu b = new Menu("");
b.addActionListener(this);
mb.add (b);
setTitle("Welcome tO Program 1 About Student Management");
setSize(360, 420);
setVisible(true);
}
public
public
public
public
public
public
public

void
void
void
void
void
void
void

windowActivated(WindowEvent we) {}
windowDeactivated(WindowEvent we) {}
windowClosing(WindowEvent we) {}
windowDeiconified(WindowEvent we) {}
windowIconified(WindowEvent we) {}
windowOpened(WindowEvent we) {}
windowClosed(WindowEvent we) {}

public void actionPerformed(ActionEvent evt)
{
String str = evt.getActionCommand();
if(str.equals("Save"))
{
try
{
int r = Integer.parseInt(tfbid.getText());
int mm = Integer.parseInt(tfbprice.getText());
//int pm = Integer.parseInt(tfpassm.getText());
st.setstudent(r,tfbnm.getText(),tfbclr.getText(),mm);
lblmsg.setText("Record Saved. ");
MyCustomListener m = new MyCustomListener();
m.setdata(str,st.getname());
}catch(Exception e)
{
lblmsg.setText(e.getMessage());
}
}
else if(str.equals("Delete"))
{
try
{
String fullname;
MyCustomListener m = new MyCustomListener();
fullname = m.getdata(str,tfbid.getText());
if (fullname == "Not Found")
lblmsg.setText("Record Not Found !");
else
lblmsg.setText("Delete" + fullname);

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar 94

2630006 – Programming Skills IV (Java)

}catch(Exception e)
{
lblmsg.setText("Sorry.. Record Not Saved !");
}
}
else if (str.equals("Exit"))
{
System.exit(0);
}
else if(str.equals("Red"))
{
}
}
public static void main(String[] args)
{
AddBoatFrame t = new AddBoatFrame();
}
}
class Student
{
int bid;
String boat_name;
String bclr;
int bprice;
Student()
{
bid=0;
boat_name="";
bclr="";
bprice=0;
}
public void setstudent(int r, String bn, String bc , int mm)
{
try
{
bid=r;
boat_name=bn;
bclr=bc;
bprice=mm;
//address=ad;
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public String getname()
{
return(bid +"," + boat_name + "," + bclr + "," + bprice);
}
}
class MyCustomListener
{
MyCustomListener()
{
}
public void setdata(String str,String val)
{
if(str.equals("Save"))
{

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar 95

2630006 – Programming Skills IV (Java)
try {
String commaSeparated = getdata("All","");
{
commaSeparated = commaSeparated + "," + val;
}
else
{
commaSeparated = commaSeparated + val;
}
File f = new File("Boat.txt");
FileWriter fw = new FileWriter(f);
fw.write(commaSeparated);
fw.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
public static String getdata(String str,String val)
{
String t;
t = "";
if(str.equals("All"))
{
try
{
File f = new File("Boat.txt");
FileReader fr = new FileReader(f);
int i;
while ( (i = fr.read() ) != -1 )
{
t = t + (char)i;
}
fr.close();
return t;
}catch(Exception e)
{
}
}
else if(str.equals("Delete"))
{
try
{
File f = new File("Boat.txt");
FileReader fr = new FileReader(f);
int i;
while ( (i = fr.read() ) != -1 )
{
t = t + (char)i;
}
fr.close();
String [] items = t.split(",");
for (int j = 0; j < items.length; j++)
{
if( items[j].equals(val) )
{
return items[j+1] + " " + items[j+2];
}
}

Enrolment No: 145253693056

Name: Pandya Meet Pankajkumar 96

2630006 – Programming Skills IV (Java) }catch(Exception e) { return "Not Found". } } Enrolment No: 145253693056 Name: Pandya Meet Pankajkumar 97 . } } return "Not Found".