Professional Documents
Culture Documents
Java Labs 8
Java Labs 8
Java Labs 8
JavaLab_8
LAB
%Lab8_1:
import java.io.* ;
class Box {
double width;
double height , depth;
}
public class BoxDemo
{
public static void main (String[] args) {
Box MyBox = new Box();
double Volume;
// assign values to MyBox's variables
MyBox.width = 10;
MyBox.height = 20 ;
MyBox.depth = 15 ;
// Compute the volume
Volume = MyBox.width *MyBox.height * MyBox.depth;
System.out.println("Volume is " + Volume);
} }
%Lab8_2:
[] J A V A
LAB
mybox2.W = 2;
mybox2.H = 3;
mybox2.D = 4;
//Display the volume of the first box
mybox1.Volume();
//Display the volume of the second box
mybox2.Volume();
} }
%Lab8_3:
import java.io.* ;
class Box {
double W, H, D;
double Volume(){
return (W * H * D);
}
}
public class Class1{
public static void main (String[] args) {
Box mybox1 = new Box();
Box mybox2 = new Box();
double Vol ;
mybox1.W = 10;
mybox1.H = 10;
mybox1.D = 10;
mybox2.W = 2;
mybox2.H = 3;
mybox2.D = 4;
//Display the volume of the first box
Vol = mybox1.Volume();
System.out.println(" Volume of the first is " + Vol);
//Display the volume of the second box
Vol = mybox2.Volume();
System.out.println(" Volume of the second is " + Vol);
}
}
------------------------------------------------------------------------------------------------------------------------------------------------Dr Mohammed Fadhl
[] J A V A
%Lab8_4:
LAB
import java.io.* ;
class Box {
double W, H, D;
double Volume() {
return (W * H * D);
}
void SetDim(double a, double b, double c) {
W = a;
H = b;
D = c;
}
}
public class Class1{
public static void main (String[] args) {
Box mybox = new Box();
double Vol ;
// Initialized the variables
mybox.SetDim(3,4,5);
//Display the volume of the first box
Vol = mybox.Volume();
System.out.println(" Volume of the first is " + Vol);
} }
%Lab8_5:
import java.io.* ;
class Box {
double W, H, D;
Box() {
System.out.println("Constructing Box");
W = 2;
H = 3;
D = 4;
}
double Volume() {
return (W * H * D);
}
}
------------------------------------------------------------------------------------------------------------------------------------------------Dr Mohammed Fadhl
[] J A V A
LAB
%Lab8_6:
import java.io.* ;
class Box {
double W, H, D;
Box(double a, double b, double c) {
System.out.println("Constructing Box");
W = a;
H = b;
D = c;
}
double Volume()
{
return (W * H * D);
}
}
public class Class1{
public static void main (String[] args) {
Box mybox1 = new Box(4,4,4);
Box mybox2 = new Box(10,10,10);
double Vol ;
Vol = mybox1.Volume();
System.out.println(" Volume of the first is " + Vol);
Vol = mybox2.Volume();
System.out.println(" Volume of the second is " + Vol);
}
}
------------------------------------------------------------------------------------------------------------------------------------------------Dr Mohammed Fadhl
[] J A V A
%Lab8_7:
LAB
class box {
" + count);