Answer to Question #54253 in Java | JSP | JSF for Nicholas

Question #54253
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.
1
Expert's answer
2015-08-27T05:32:06-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

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

LATEST TUTORIALS
APPROVED BY CLIENTS