Add OOP/Java/Lab/Week5/Box.java
This commit is contained in:
parent
5d71be06a8
commit
9e7c46ea8d
33
OOP/Java/Lab/Week5/Box.java
Normal file
33
OOP/Java/Lab/Week5/Box.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user