Answered step by step
Verified Expert Solution
Link Copied!

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 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(50);
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(50);
System.out.println("Resized Rectangle - Length: "+ rectangle.getLength()+", Width: "+ rectangle.getWidth());
}
}
Sample output:
Circle:
Name: Circle
Color: Red
Radius: 5.0
Area: 78.53981633974483
Perimeter: 31.41592653589793
Resized Circle - Radius: 7.5
Rectangle:
Name: Rectangle
Color: Blue
Length: 4.0
Width: 6.0
Area: 24.0
Perimeter: 20.0
Resized Rectangle - Length: 6.0, Width: 9.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago