Question: Purpose: To write an Object-Oriented application using abstraction, inheritance, encapsulation, and polymorphism to handle an inheritance structure of various shapes. Details: Implement the following Shape

Purpose: To write an Object-Oriented application using abstraction, inheritance, encapsulation, and polymorphism to handle an inheritance structure of various shapes.

Details:

Implement the following Shape hierarchy:

Shape

/ | \

Circle Square Triangle

Use the following as a guide:

The Shape class should be abstract and contain two abstract methods:

getArea Which calculates the area of the shape and returns that value as a double.

getPerimeter Which calculates the perimeter of the shape and return that value as a double.

And one concrete method:

getName that returns the shapes name as a String.

The Circle classs constructor should take a single parameter of type double representing its diameter. No error checking is required.

The Square classs constructor should take a single parameter of type double representing the length of its sides. No error checking is required.

The Triangle classs constructor should take a single parameter of type double representing the length of its sides. No error checking is required.

No set and get methods are needed. Do not include them in the any of the classes.

Create a second class called TestShapes that contains the main method. This test class does not need to ask users for input. The class should do the following:

Create an array of size three, that uses Shape references. Fill the array with one of each concrete class in the hierarchy.

Iterate through the array of shapes and doing the following:

Display the shapes name.

Display the shapes area.

Display the shapes perimeter.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!