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

Recommended Textbook for

Logistics Lifeline Supply Chain Strategies

Authors: Ehsan Sheroy

1st Edition

7419377502, 978-7419377503

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago

Question

What is RAM as far as telecommunication is concerned?

Answered: 1 week ago

Question

Question 1: What is reproductive system? Question 2: What is Semen?

Answered: 1 week ago

Question

Describe the sources of long term financing.

Answered: 1 week ago

Question

5. Identify the logical fallacies, deceptive forms of reasoning

Answered: 1 week ago

Question

6. Choose an appropriate organizational strategy for your speech

Answered: 1 week ago