From 9e7c46ea8dc5fc66ad9c4dac0a7ae8097f968b2c Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 31 Aug 2024 02:16:27 +0530 Subject: [PATCH] Add OOP/Java/Lab/Week5/Box.java --- OOP/Java/Lab/Week5/Box.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 OOP/Java/Lab/Week5/Box.java diff --git a/OOP/Java/Lab/Week5/Box.java b/OOP/Java/Lab/Week5/Box.java new file mode 100644 index 0000000..7d8e3de --- /dev/null +++ b/OOP/Java/Lab/Week5/Box.java @@ -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()); + } +}