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
;
Rectangle rectangle
new Rectangle
Rectangle
Blue
;
System.out.println
Circle:
;
System.out.println
Name:
circlegetName
;
System.out.println
Color:
circlegetColor
;
System.out.println
Radius:
circlegetRadius
;
System.out.println
Area:
circlecalculateArea
;
System.out.println
Perimeter:
circlecalculatePerimeter
;
circle.resize
;
System.out.println
Resized Circle
Radius:
circlegetRadius
;
System.out.println
Rectangle:"
;
System.out.println
Name:
rectanglegetName
;
System.out.println
Color:
rectanglegetColor
;
System.out.println
Length:
rectanglegetLength
;
System.out.println
Width:
rectanglegetWidth
;
System.out.println
Area:
rectanglecalculateArea
;
System.out.println
Perimeter:
rectanglecalculatePerimeter
;
rectangle.resize
;
System.out.println
Resized Rectangle
Length:
rectanglegetLength
Width:
rectanglegetWidth
;
Sample output:
Circle:
Name: Circle
Color: Red
Radius:
Area:
Perimeter:
Resized Circle
Radius:
Rectangle:
Name: Rectangle
Color: Blue
Length:
Width:
Area:
Perimeter:
Resized Rectangle
Length:
Width:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
