My excuted programs

Sunday, July 1, 2007

Java assignments week1 :part 3 Q.15- Q27

Question 15 Box class


class Box{
double width;
double height;
double depth ;
}

screen shot



Question 16

class BoxTest{
public static void main (String arg[]){
Box b1 = new Box();
double vol;

b1.width = 10;
b1.height = 20;
b1.depth = 15;

vol = b1.width*b1.height*b1.depth;
System.out.println("Volume is :" + vol);

}
}

Screen shot

Question 17


class BoxTest1{
public static void main (String arg[]){
Box b1 = new Box();
Box b2 = new Box();
double vol;
b1.width = 10;
b1.height = 20;
b1.depth = 15;
vol = b1.width*b1.height*b1.depth;
System.out.println("Volume is :" + vol);

b2.width = 3;
b2.height = 6;
b2.depth = 9;
vol = b2.width*b2.height*b2.depth;
System.out.println("Volume is :" + vol);
}
}

Screen shots
Photo Sharing and Video Hosting at Photobucket

Question 19:

class BoxTest2{
public static void main (String arg []){
Box1 b1 = new Box1();
Box1 b2 = new Box1();
double vol;

b1.width = 10;
b1.height = 20;
b1.depth = 15;

b2.width = 3;
b2.height = 6;
b2.depth = 9;

b1.volume();
b2.volume();

}
}



Screen Shot
Photo Sharing and Video Hosting at Photobucket
Photo Sharing and Video Hosting at Photobucket

Question 20

class Box2{

double width;
double height;
double depth ;

double volume (){
return width*height*depth;


}

}


Screen Shots
(Coding on notepad)
Photo Sharing and Video Hosting at Photobucket
(Runtime screen)
Photo Sharing and Video Hosting at Photobucket


Question 21

class BoxTest4{
public static void main(String arg[]){
Box2 b1 = new Box2();
Box2 b2 = new Box2();
double vol;


b1.setDim(10,20,15);
b2.setDim(3,6,9);

vol = b1.width*b1.height*b1.depth;
System.out.println("Volume is :" + vol);


vol = b2.width*b2.height*b2.depth;
System.out.println("Volume is :" + vol);

}
}


Screen Shots
(Runtime Screen)

Photo Sharing and Video Hosting at Photobucket


Question 22

class Box3{

double width;
double height;
double depth ;

double volume (){
return width*height*depth;

}
void setDim (double w , double h , double d){
width = w ;
height = h ;
depth = d ;

}

}


Screen Shots
(Notepad)
Photo Sharing and Video Hosting at Photobucket

(Runtime screen)
Photo Sharing and Video Hosting at Photobucket


Question 23

class BoxTest4{
public static void main(String arg[]){
Box3 b1 = new Box3();
Box3 b2 = new Box3();
double vol;


b1.setDim(10,20,15);
b2.setDim(3,6,9);

vol = b1.width*b1.height*b1.depth;
System.out.println("Volume is :" + vol);


vol = b2.width*b2.height*b2.depth;
System.out.println("Volume is :" + vol);

}
}


ScreenShots

(Notepad)
Photo Sharing and Video Hosting at Photobucket

(Runtime)
Photo Sharing and Video Hosting at Photobucket

Question 24

class Box4{

double width;
double height;
double depth ;



Box4(){
System.out.println("Constructing a box");
width = 10 ;
height= 20 ;
depth = 15;
}

double volume (){
return width*height*depth;


}

}


Screen shots
(Notepad)
Photo Sharing and Video Hosting at Photobucket

(Runtime)
Photo Sharing and Video Hosting at Photobucket

Question 25

class BoxTest5{
public static void main(String arg[]){
Box4 b1 = new Box4();
Box4 b2 = new Box4();
double vol;

vol = b1.volume();
System.out.println("Volume is :" + vol);

vol = b2.volume();
System.out.println("Volume is :" + vol);

}
}



Screen Shot

(runtime)
Photo Sharing and Video Hosting at Photobucket

Question 26

class Box5{

double width;
double height;
double depth ;



Box5(double w , double h , double d){
width = w;
height = h;
depth = d;
}

double volume (){
return width*height*depth;


}

}



Screen Shots
(Notepad)
Photo Sharing and Video Hosting at Photobucket

Question 27

class BoxTest6 {
public static void main(String arg []){
Box5 b1 = new Box5 (10,20,15);
Box5 b2 = new Box5 (3,6,9);
double vol ;

vol = b1.volume();
System.out.println ("Volume is :" + vol );

vol = b2.volume();
System.out.println ("Volume is :" + vol) ;



}
}


Screen Shots

Photo Sharing and Video Hosting at Photobucket








No comments: