Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an interactive program that computes the volume of a 3-dimensional object.

ID: 3621446 • Letter: W

Question

Write an interactive program that computes the volume of a 3-dimensional object. The program must prompt the user to enter (1) the geometric object type (cylinder or rectangular prism, i.e., a 3 dimensional rectangle), (2) the base dimension (side length or radius) and (3) the height of the object. Your solution must contain 3 classes – one that computes the area of the base, a second that computes the volume of the shape using the base area computed in class one, and a third that gets user input and displays the computed volume values and type of geometric object. The demo class must continue to get user input until the user answers “no” to a program-ending question such as “Do you want to continue?”.
Suggested class names are Base, Shape, and ShapeDemo. Use private variables and accessor methods to get the values of the variables. Also include mutator methods that compute area and volume. Make your classes and methods as cohesive as possible.

Explanation / Answer

public class Base { private double baseDimension; private double baseDimension2; public Base(double baseDimension, double baseDimension2) { this.baseDimension = baseDimension; this.baseDimension2 = baseDimension2; } public Base(double baseDimension) { this.baseDimension = baseDimension; this.baseDimension2 = 0; } public double getBaseDimension() { return baseDimension; } public double getbaseDimension2() { return baseDimension2; } public void setBaseDimension(double baseDimension) { this.baseDimension = baseDimension; } public void setBaseDimension2(double baseDimension) { this.baseDimension2 = baseDimension; } public double getBaseAreaCylinder() { return (baseDimension * baseDimension) * Math.PI; } public double getBaseAreaRectangle() { return baseDimension * baseDimension2; } } public class Shape { public static double volumeCylinder(double radius, double height){ Base base = new Base(radius); double baseArea = base.getBaseAreaCylinder(); return baseArea * height; } public static double volumeRectangle(double sideLength, double sideLength2, double height) { Base base = new Base(sideLength, sideLength2); double baseArea = base.getBaseAreaRectangle(); return baseArea * height; } } import java.util.Scanner; public class ShapeDemo { public static void main(String[] args) { Scanner input = new Scanner(System.in); Scanner input2 = new Scanner(System.in); int x=0; double height, baseDimension; int baseDimension2; String quit; while (x==0) { System.out.println("Enter the dimensions with height first (if there is only 2 dimensions enter 0 for the last one)"); System.out.print("i.e. (1 2 3) or (1 2 0)"); height = input.nextInt(); baseDimension = input.nextInt(); baseDimension2 = input.nextInt(); if (baseDimension2 == 0) { System.out.println("Cylinder Volume: " + Shape.volumeCylinder(baseDimension, height)); } else { System.out.println("Rectangle Volume: " + Shape.volumeRectangle(baseDimension, (double)baseDimension2, height)); } System.out.print("Do you want to continue? "); quit = input2.nextLine(); if (quit.equalsIgnoreCase("no")) x = 1; } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote