-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab05_2_630510606.java
58 lines (47 loc) · 1.26 KB
/
Lab05_2_630510606.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Anawin Athawong
630510606
*/
import java.util.Scanner;
class Box {
private float width, height, length, volume;
private String name;
public Box() {
System.out.printf("Hello from 2nd constructor\n");
};
public Box(String a, float x, float y, float z) {
System.out.printf("Hello from 1st constructor\n");
name = a;
width = x;
length = y;
height = z;
}
public void setData() {
Scanner input = new Scanner(System.in);
System.out.print("Input Name of Box: ");
name = input.nextLine();
System.out.print("Input Width: ");
width = input.nextFloat();
System.out.print("Input Length: ");
length = input.nextFloat();
System.out.print("Input Height: ");
height = input.nextFloat();
}
public void calVolume() {
volume = width * length * height;
}
public void display() {
System.out.printf("The volume of Box: %s = %.1f \n", name, volume);
}
}
public class Lab05_2_630510606 {
public static void main(String[] args) {
Box a = new Box("SizeA", 14, 20, 6);
a.calVolume();
a.display();
Box b = new Box();
b.setData();
b.calVolume();
b.display();
}
}