Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java interface Shape that has the following methods: double getArea(): This method should return the area of the shape. double getPerimeter(): This method

Create a Java interface Shape that has the following methods:
double getArea(): This method should return the area of the shape.
double getPerimeter(): This method should return the perimeter of the shape.
Create an abstract class AbstractShape that implements the Shape interface and has the following attributes:
color (a string)
The class should have the following methods:
setColor(String color): This method should set the color of the shape.
getColor(): This method should return the color of the shape.
Create a class Rectangle that extends the AbstractShape class and has the following attributes:
width (a double)
height (a double)
The class should have the following methods:
setWidth(double width): This method should set the width of the rectangle.
setHeight(double height): This method should set the height of the rectangle.
getWidth(): This method should return the width of the rectangle.
getHeight(): This method should return the height of the rectangle.
getArea(): This method should return the area of the rectangle, which is calculated as width * height.
getPerimeter(): This method should return the perimeter of the rectangle, which is calculated as 2 * (width + height).
toString(): This method should return a string representation of the rectangle, including its width, height, color, and area and perimeter.
Create a class Circle that extends the AbstractShape class and has the following attribute:
radius (a double)
The class should have the following methods:
setRadius(double radius): This method should set the radius of the circle.
getRadius(): This method should return the radius of the circle.
getArea(): This method should return the area of the circle, which is calculated as * radius * radius.
getPerimeter(): This method should return the circumference of the circle, which is calculated as 2 * * radius.
toString(): This method should return a string representation of the circle, including its radius, color, and area and perimeter.
In the Main class, create two Rectangle objects and two Circle objects, set their attributes, and demonstrate the use of each of the methods.

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago