Answer to Question #54253 in Java | JSP | JSF for Nicholas
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
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.
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
There are certain things that people in the business world frown upon. Things like lows in the economy, housing crisis,…
APPROVED BY CLIENTS
It's hard to get straightforward feedback for programming assignments, usually it's like pulling teeth when you just want to flat out see where you went wrong so you can improve. Worth the (reasonable) payment. 5/5