-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBoxDemo.java
More file actions
34 lines (28 loc) · 910 Bytes
/
Copy pathBoxDemo.java
File metadata and controls
34 lines (28 loc) · 910 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
/* 1. Complete the following a program in Java to create a class Box with instance variables length,
width, and height. Create at least 2 objects from the class Box and calculate volume of each box
object. */
// this class declares an object of type box
class Box{
int length;
int width;
int height;
}
public class BoxDemo {
public static void main(String[] args) {
Box box1=new Box();
Box box2=new Box();
double vol1,vol2;
//assign values of box instance variables
box1.length=6;
box1.height=7;
box1.width =8;
box2.length=12;
box2.width =43;
box2.height=3;
// compute volume
vol1= box1.length*box1.width *box1.height;
vol2= box2.length*box2.width *box2.height;
System.out.println("Volume of box1 is : "+vol1);
System.out.println("Volume of box2 is : "+vol2);
}
}