Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please implement all methods and prompts for every class outputting sample outputs below.... Create an abstract class named Shape with the following properties and methods:
please implement all methods and prompts for every class outputting sample outputs below....
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 resizeint 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 eg 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 mainString args
Circle circle new CircleCircle "Red", ;
Rectangle rectangle new RectangleRectangle "Blue", ;
System.out.printlnCircle:;
System.out.printlnName: circle.getName;
System.out.printlnColor: circle.getColor;
System.out.printlnRadius: circle.getRadius;
System.out.printlnArea: circle.calculateArea;
System.out.printlnPerimeter: circle.calculatePerimeter;
circle.resize;
System.out.printlnResized Circle Radius: circle.getRadius;
System.out.println
Rectangle:";
System.out.printlnName: rectangle.getName;
System.out.printlnColor: rectangle.getColor;
System.out.printlnLength: rectangle.getLength;
System.out.printlnWidth: rectangle.getWidth;
System.out.printlnArea: rectangle.calculateArea;
System.out.printlnPerimeter: rectangle.calculatePerimeter;
rectangle.resize;
System.out.printlnResized Rectangle Length: rectangle.getLength Width: rectangle.getWidth;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started