****IN JAVAAA****** Write a program where a user populates a collection of vario
ID: 3707096 • Letter: #
Question
****IN JAVAAA******
Write a program where a user populates a collection of various shapes, which is sorted by its area. The user should be able to specify which type of shape they wish to enter, and then are prompted with the pertinent information which will be used to calculate the shape’s area.
Requirements:
The types of shapes the user can enter are:
Circle
Rectangle
Triangle
The structure of the program should follow this UML class diagram.
You may also include helper methods that are not noted in the class diagram, but its overall class structure should be what is shown above.
Example Output:
Welcome to the Shapes collections
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
1
What type of shape?
Rectangle, Triangle, or Circle?
Rectangle
Enter a length followed by a height
3.0 4.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
1
What type of shape?
Rectangle, Triangle, or Circle?
Triangle
Enter a base followed by a height
4.0 5.0
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
1
What type of shape?
Rectangle, Triangle, or Circle?
Circle
Enter a radius
5
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Circle Radius 5.0 Area 78.53981633974483
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
1
What type of shape?
Rectangle, Triangle, or Circle?
Rectangle
Enter a length followed by a height
-1.0 5.0
Invalid length
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Circle Radius 5.0 Area 78.53981633974483
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
1
What type of shape?
Rectangle, Triangle, or Circle?
Triangle
Enter a base followed by a height
6.0 7.0
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Triangle Base 6.0 Height 7.0 Area 21.0
Circle Radius 5.0 Area 78.53981633974483
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
2
Enter the shape type
Triangle
Enter an area
21
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Circle Radius 5.0 Area 78.53981633974483
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
2
Enter the shape type
Circle
Enter an area
10
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Circle Radius 5.0 Area 78.53981633974483
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
21
Invalid Input
Triangle Base 4.0 Height 5.0 Area 10.0
Rectangle Length 3.0 Height 4.0 Area 12.0
Circle Radius 5.0 Area 78.53981633974483
Enter 1: Add a shape
Enter 2: Remove a shape
Enter 9: Quit
9
Good bye
ShapeCollection - shapes: Shapell ShapeFrontEnd + addShape(Shape): void - sortShapes): void + removeShape(String,double): void + printShapes():void + static main(Stringll args):void Shape + getArea0:double + toString(): String + getShapeType: String Rectangle Triangle Circle - base: double height: double + getBase(): double - length: double - width: double + getLength(): double +setLength(double): void setBase(double): void + getWidth): double + setWidth(double): voidsetHeight(double): void - radius: double +getRadius(): double +setRadius(double): void + getHeight(): doubleExplanation / Answer
Shape.java
public interface Shape {
double getArea();
String toString();
String getShapeType();
}
____________
Circle.java
public class Circle implements Shape {
private double radius;
@Override
public double getArea() {
return Math.PI*radius*radius;
}
@Override
public String getShapeType() {
return "Circle";
}
@Override
public String toString() {
return "Circle [radius=" + radius + " Area = "+getArea()+"]";
}
}
__________________
Rectangle.java
public class Rectangle implements Shape {
private double length;
public double height;
@Override
public double getArea() {
return length*height;
}
@Override
public String getShapeType() {
return "Rectangle";
}
@Override
public String toString() {
return "Rectangle [length=" + length + ", height=" + height + "Area = "+getArea()+"]";
}
}
_________________
Triangle.java
public class Triangle implements Shape {
private double base;
private double height;
@Override
public double getArea() {
return base*height;
}
@Override
public String getShapeType() {
return "Triangle";
}
@Override
public String toString() {
return "Triangle [base=" + base + ", height=" + height + " Area = "+getArea()+"]";
}
}
_________________
I will develop the remaining classes also..Thank u
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.