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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage