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

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


Question 20
class Box2{
double width;
double height;
double depth ;
double volume (){
return width*height*depth;
}
}
Screen Shots
(Coding on notepad)

(Runtime screen)

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)

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)

(Runtime screen)

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)

(Runtime)

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)

(Runtime)

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)

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)

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




No comments:
Post a Comment