-
Notifications
You must be signed in to change notification settings - Fork 0
/
Box.java
90 lines (89 loc) · 1.49 KB
/
Box.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Created by Noah Shaw
*/
public class Box {
//Instance variables
private String label;
private double length;
private double width;
private double height;
//Constructors
public Box()
{
this.label = "None";
this.length = 1.0;
this.width = 1.0;
this.height = 1.0;
}
public Box(String aLabel, double aLength, double aWidth, double aHeight)
{
this.setLabel(aLabel);
this.setLength(aLength);
this.setWidth(aWidth);
this.setHeight(aHeight);
}
//Accessors
public String getLabel()
{
return this.label;
}
public double getLength()
{
return this.length;
}
public double getWidth()
{
return this.width;
}
public double getHeight()
{
return this.height;
}
//Mutators
public void setLabel(String aLabel)
{
this.label = aLabel;
}
public void setLength(double aLength)
{
if(aLength > 0)
{
this.length = aLength;
}
else
{
System.out.println("Invalid length.");
}
}
public void setWidth(double aWidth)
{
if(aWidth > 0)
{
this.width = aWidth;
}
else
{
System.out.println("Invalid width.");
}
}
public void setHeight(double aHeight)
{
if(aHeight > 0)
{
this.height = aHeight;
}
else
{
System.out.println("Invalid height.");
}
}
//Other methods
public double getVolume()
{
return this.length * this.width * this.height;
}
public String toString()
{
return this.label + ": " + (this.length * this.width * this.height);
}
}