-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxDemo2.java
More file actions
34 lines (29 loc) · 776 Bytes
/
BoxDemo2.java
File metadata and controls
34 lines (29 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* A program that uses Box class
call this file BoxDemo.java
*/
class Box{
double width;
double height;
double depth;
}
class BoxDemo2{
public static void main(String args[]){
Box mybox1 = new Box();
Box mybox2 =new Box();
double vol;
//assign values to mybox1's instance variables
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
//assign values to mybox2's instance variables
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
//compute volume of the mybox1
vol = mybox1.width * mybox1.height * mybox1.depth;
System.out.println("Volume is " + vol);
//compute volume of the mybox1
vol = mybox2.width * mybox2.height * mybox2.depth;
System.out.println("Volume is " + vol);
}
}