Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Exercise 0 4 1 . Shape Hierarchy: - Create a base class called Shape with the following attributes and methods: - Attributes: ` color

Programming Exercise 04
1. Shape Hierarchy:
- Create a base class called Shape with the following attributes and methods:
- Attributes: `color`(String) and `filled`(boolean).
- Methods:
-`getArea()`(abstract method)
-`getPerimeter()`(abstract method)
-`toString()` method that returns a string representation of the shape.
- Create two subclasses, `Circle` and `Rectangle`, that are inherited from the `Shape` class.
-`Circle` should have a `radius` attribute.
-`Rectangle` should have `width` and `length` attributes.
- Implement appropriate constructors and override the abstract methods in the subclasses.
2. Polymorphic Array:
- In the main class, create an array of `Shape` objects.
- Populate the array with instances of `Circle` and `Rectangle`.
- Display the details (color, filled, area, and perimeter) of each shape using polymorphism.
3. Interface:
- Define an interface called `Resizable` with a method `resize(double factor)` that represents resizing a shape.
- Make the `Rectangle` class implement the `Resizable` interface.
- In the main class, demonstrate polymorphism by resizing a `Rectangle` object using the `Resizable` interface.
An example of the program is shown below:

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

Students also viewed these Databases questions