-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5Box.java
More file actions
38 lines (31 loc) · 985 Bytes
/
Lab5Box.java
File metadata and controls
38 lines (31 loc) · 985 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
35
36
37
38
class Lab5Box {
double length;
double width;
double height;
public Lab5Box(double length, double width, double height) {
this.length = length;
this.width = width;
this.height = height;
}
public Lab5Box(double length, double width) {
this.length = length;
this.width = width;
this.height = 1;
}
public Lab5Box(double length) {
this.length = length;
this.width = 1;
this.height = 1;
}
public double volume() {
return length * width * height;
}
public static void main(String[] args) {
Lab5Box box1 = new Lab5Box(5, 3, 2);
System.out.println("Volume of Box 1: " + box1.volume());
Lab5Box box2 = new Lab5Box(4, 2);
System.out.println("Volume of Box 2: " + box2.volume());
Lab5Box box3 = new Lab5Box(3);
System.out.println("Volume of Box 3: " + box3.volume());
}
}