34 lines
836 B
Java
34 lines
836 B
Java
|
import java.util.Scanner;
|
||
|
|
||
|
class Box {
|
||
|
|
||
|
double width;
|
||
|
double height;
|
||
|
double depth;
|
||
|
|
||
|
public void setDimensions(double w, double h, double d) {
|
||
|
width = w;
|
||
|
height = h;
|
||
|
depth = d;
|
||
|
}
|
||
|
|
||
|
public double getVolume() {
|
||
|
return width * height * depth;
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
Scanner sc = new Scanner(System.in);
|
||
|
Box myBox = new Box();
|
||
|
|
||
|
System.out.print("Enter the width of the box:");
|
||
|
int width = sc.nextInt();
|
||
|
System.out.print("Enter the height of the box:");
|
||
|
int height = sc.nextInt();
|
||
|
System.out.print("Enter the depth of the box:");
|
||
|
int depth = sc.nextInt();
|
||
|
|
||
|
myBox.setDimensions(width, height, depth);
|
||
|
System.out.println("The volume of the box is: " + myBox.getVolume());
|
||
|
}
|
||
|
}
|