Add OOP/Java/Lab/Week5/Box.java

This commit is contained in:
Aadit Agrawal 2024-08-31 02:16:27 +05:30
parent 5d71be06a8
commit 9e7c46ea8d

View 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());
}
}