Question: Create an abstract class named Shape with the following properties and methods: Properties: name ( String ) and color ( String ) . Abstract methods:

Create an abstract class named Shape with the following properties and methods:
Properties: name
(
String
)
and color
(
String
)
.
Abstract methods: calculateArea
(
)
and calculatePerimeter
(
)
.
Create two subclasses of Shape named Circle and Rectangle. Implement the abstract methods in each subclass to calculate the area and perimeter of the respective shapes.
Circle should have a constructor that accepts the radius as a parameter.
Rectangle should have a constructor that accepts the length and width as parameters.
Create an interface named Resizable with a method resize
(
int percent
)
that should be implemented by the Circle and Rectangle classes. The resize method should increase or decrease the dimensions of the shape by the given percentage.
Create a main class ShapeTest to test your implementation. Create instances of Circle and Rectangle, set their properties, calculate their areas and perimeters, and resize them using the Resizable interface.
Bonus
(
Optional
)
: Implement additional shapes
(
e
.
g
.
,
Triangle, Square
)
as subclasses of Shape and provide appropriate implementations for calculating area, perimeter, and resizing.
The following test code should then output the Circle and Rectangle objects:
public class ShapeTest
{
public static void main
(
String
[
]
args
)
{
Circle circle
=
new Circle
(
"
Circle
"
,
"Red",
5
)
;
Rectangle rectangle
=
new Rectangle
(
"
Rectangle
"
,
"Blue",
4
,
6
)
;
System.out.println
(
"
Circle:
"
)
;
System.out.println
(
"
Name:
"
+
circle.getName
(
)
)
;
System.out.println
(
"
Color:
"
+
circle.getColor
(
)
)
;
System.out.println
(
"
Radius:
"
+
circle.getRadius
(
)
)
;
System.out.println
(
"
Area:
"
+
circle.calculateArea
(
)
)
;
System.out.println
(
"
Perimeter:
"
+
circle.calculatePerimeter
(
)
)
;
circle.resize
(
5
0
)
;
System.out.println
(
"
Resized Circle
-
Radius:
"
+
circle.getRadius
(
)
)
;
System.out.println
(
"
Rectangle:"
)
;
System.out.println
(
"
Name:
"
+
rectangle.getName
(
)
)
;
System.out.println
(
"
Color:
"
+
rectangle.getColor
(
)
)
;
System.out.println
(
"
Length:
"
+
rectangle.getLength
(
)
)
;
System.out.println
(
"
Width:
"
+
rectangle.getWidth
(
)
)
;
System.out.println
(
"
Area:
"
+
rectangle.calculateArea
(
)
)
;
System.out.println
(
"
Perimeter:
"
+
rectangle.calculatePerimeter
(
)
)
;
rectangle.resize
(
5
0
)
;
System.out.println
(
"
Resized Rectangle
-
Length:
"
+
rectangle.getLength
(
)
+
"
,
Width:
"
+
rectangle.getWidth
(
)
)
;
}
}
Sample output:
Circle:
Name: Circle
Color: Red
Radius:
5
.
0
Area:
7
8
.
5
3
9
8
1
6
3
3
9
7
4
4
8
3
Perimeter:
3
1
.
4
1
5
9
2
6
5
3
5
8
9
7
9
3
Resized Circle
-
Radius:
7
.
5
Rectangle:
Name: Rectangle
Color: Blue
Length:
4
.
0
Width:
6
.
0
Area:
2
4
.
0
Perimeter:
2
0
.
0
Resized Rectangle
-
Length:
6
.
0
,
Width:
9
.
0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!