In: Computer Science
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and a RectangularPrismDemo class. --------------------------------------------------------------------------------------------------------------------------------------- RectangularPrism |
- length: double - width: double - height: double |
+ RectangularPrism() + RectangularPrism(l:double,w:double, h:double) + setLength(l:double):void + setWidth(w:double):void + setHeight(h:double):void +getLength():double +getWidth():double +getHeight():double +getVolume():double +getSurfaceArea():double +toString():String ---------------------------------------------------------------------------------------------------------------------
|
thanks for the question, here are the two classes - RectangularPRism.java and RectangularPRismDemo.java with screenshot fo the output
======================================================================================
public class RectangularPrism { private double length; private double width; private double height; public RectangularPrism() { this.length = 0; this.width = 0; this.height = 0; } public RectangularPrism(double length, double width, double height) { this.length = length; this.width = width; this.height = height; } public void setLength(double length) { this.length = length; } public void setWidth(double width) { this.width = width; } public void setHeight(double height) { this.height = height; } public double getLength() { return length; } public double getWidth() { return width; } public double getHeight() { return height; } public double getVolume() { return getHeight() * getLength() * getWidth(); } public double getSurfaceArea() { return 2 * (getWidth() * getLength() + getWidth() * getHeight() + getLength() * getHeight()); } @Override public String toString() { return "Length: " + getLength() + ", Width: " + getWidth() + ", Height: " + getHeight() + ", Volume: " + getVolume() + ", Surface Area: " + getSurfaceArea(); } }
===============================================================================================
public class RectangularPrismDemo { public static void main(String[] args) { RectangularPrism prismOne = new RectangularPrism(); RectangularPrism prismTwo = new RectangularPrism(6,4,10); prismOne.setLength(10); prismOne.setHeight(12); prismOne.setWidth(8); System.out.printf("Prism Two Height: "+prismTwo.getHeight()); System.out.printf("\nPrism Two Length: "+prismTwo.getLength()); System.out.printf("\nPrism Two Width: "+prismTwo.getWidth()); System.out.printf("\nPrism One: "+prismOne); System.out.printf("\nPrism Two: "+prismTwo); } }
===============================================================================================