Create 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.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create 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.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images