Question: JAVA Implement the following UML Diagram. Note: Shape is an abstract class Shape is an abstract class and the method calculateArea is an abstract method
JAVA
Implement the following UML Diagram. Note: Shape is an abstract class
Shape is an abstract class and the method calculateArea is an abstract method the constructor in the Shape class is a no args constructor and sets area to 0. The Shape toString method returns the area to 2 decimal places**
Circle class extends from Shape. The constructor sets the radius from a value passed in the constructor. The constructor also calls the calculateArea method The calculateArea method calculates the area and calls the setArea method to store the area The toString method also sets the radius to 2 decimal places
To control the format for decimals in the toString method, you can use the DecimalFormat class (import java.text.DecimalFormat)
Here is an example of how it works:
public String toString() { //assume you are print some calculation value [value] that has several decimal places and you //want it to print only 2 decimal places DecimalFormat df = new DecimalFormat("#.00"); //give it the format return "Value is : " + df.format(value); //changes double value to have 2 decimal places } Write a demo program, that will use a Scanner to read the attributes to create a Circle object (radius), and then print the Circle object.
Input
The radius of a circle
Example Input: 78.2
Output
The radius and area of the circle
Example Output: Radius: 78.20 Area: 19211.59
Shape - area double + Shape () + getArea (): double setArea double) void + abstract calculateArea() + toString ): String void Circle - radius: double +Circle (rad: double) +getRadius ():double +setRadius. ( double) : void +toString () : String + calculateArea) voidStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
