Each class must have private instance fields that store the specific shapes dimensions.
Each class must have a constructor that supplies the dimensions.
Each class must have an area() function.
Each class must have a toString() function that returns strings like these, as appropriate:
∗ triangle (base = 1.00, height = 2.00)
∗ rectangle (width = 1.00, height = 1.00)
∗ square (side = 1.00)
∗ circle (radius = 1.00)
All numbers are rounded to two decimal places.
Write a Main class that works like this:
$ java Main
?triangle 1.0 2.0
Area of triangle (base = 1.00, height = 2.00) = 1.00
? rectangle 1.0 2.0
Area of rectangle (width = 1.00, height = 2.00) = 2.00
? square 1.0
Area of square (side = 1.00) = 1.00
? circle 1.0
Area of circle (radius = 1.00) = 3.14
? quit
$
It does not need to handle bad user input.
Hint: Your Main class will be simpler if you exploit inclusion polymorphism. Have a single variable
of type Shape, instead of many variables with different types.
The answer to the question is available in the PDF file https://www.assignmentexpert.com/https://www.assignmentexpert.com/homework-answers/programming-answer-54253.pdf
Learn more about our help with Assignments: JavaJSPJSF
Comments
Assignment Expert
28.08.15, 18:25
Dear Nick, please pay attention to the code structure: there are 6
separate java files in the project (TestShape.java, Circle.java,
Rectangle.java, Shape.java, Square.java and Triangle.java). When you
place the code in each file, please type in the command line $ javac
*.java $ java TestShape
Nick
28.08.15, 08:33
This doesn't work for me. Am I missing something?
Leave a comment
Thank you! Your comments have been successfully added. However, they need to be checked by the moderator before being published.
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Dear Nick, please pay attention to the code structure: there are 6 separate java files in the project (TestShape.java, Circle.java, Rectangle.java, Shape.java, Square.java and Triangle.java). When you place the code in each file, please type in the command line $ javac *.java $ java TestShape
This doesn't work for me. Am I missing something?
Leave a comment