-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackage.java
61 lines (48 loc) · 1.39 KB
/
Package.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
package Project2;
import java.util.Scanner;
public class Package {
//3 private instance variables - length, width and height
private double length, width, height;
//1 private instance variable (type - scanner)
private Scanner input = new Scanner(System.in);
//no args public constructor - initialize all three instance variables to 1.0
public Package()
{
this.length = this.width = this.height = 1.0;
}
//Initial public constructor – initialize all three instance variables
public Package(double length, double width, double height)
{
this.length = length;
this.width = width;
this.height = height;
}
//Copy constructor – copy Package
public Package(Package b)
{
this(b.length, b.width, b.height);
}
//inputWidth, inputLength, and inputHeight methods
public void inputWidth()
{
this.width = input.nextDouble();
}
public void inputLength()
{
this.length = input.nextDouble();
}
public void inputHeight()
{
this.height = input.nextDouble();
}
//displayDimensions method
public void displayDimensions()
{
System.out.printf("%.1f X %.1f X %.1f", length, width, height);
}
//calcVolume method that has no parameters and calculates the volume
public double calcVolume()
{
return length * width * height;
}
}