Question: I need an abstract class called Shape with the protected member String shapeName. It should have two public abstract methods getArea and getVolume . Finally,
I need an abstract class called Shape with the protected member String shapeName. It should have two public abstract methods getArea and getVolume. Finally, it should contain a public String method called getName which returns the shapeName. You should create a Circle class, Square class, Rectangle class, Triangle class which extend the Shape class.
Each class should contain the necessary private variables. For example, a square has a side. The area and the volume can all be derived from the side value so the only private variable necessary for the square class is the side. The circle requires a radius. The triangle requires a base, length and a height. Finally, the rectangle requires length, height and width. The classes should also contain constructors and appropriate implementations of the two abstract methods getArea and the getVolume.
**Shape Calculator** Enter 1 for a Circle Enter 2 for a Square Enter 3 for a Rectangle Enter 4 for a Triangle Enter 5 to Exit
You should use a menu with a case/switch statement that allows the user to choose which shape they want. After the user enters their choice, ask them to enter the necessary information, perform the calculations and display the area and volume for the shape the user chose. The program should continue to allow the user to choose shapes and display the results until the user enters 5 to exit.
Triangle volume: length * base * height/3 Triangle area: base * height/2 Circle area: Math.PI * radius * radius Circle volume: 4/3 * Math.PI * radius * radius * radius Square area: side * side
Square volume: side * side * side Rectangle area: length * width Rectangle volume: length * width * height
Be sure to verify the user enters positive numbers and limit the display to 2 decimals. Any thoughts would be helpful . Getting errors on my output .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
