Question: In this task, your code creates a random list of 100 shape objects, then traverses the list from start to end, and computes the total

In this task, your code creates a random list of 100 shape objects, then traverses the list

from start to end, and computes the total area of the shape objects. First you need to implement the class

hierarchy diagram of the shape types, which is attached. Shape is an abstract class which has only a "color"

attribute whereas Circle class and Rectangle class are concrete children of Shape class, and they have more

attributes and constructors. Note that you do not know beforehand the order of the shape objects (i.e.

Circles and Rectangles) created in the random list, e.g. you do not know beforehand whether the 1st item

is Circle or Rectangle.

Writing README carries 1 point.

Note. When you traverse the list to calculate the total area, you call the area() function of each shape object

(without considering if it is Rectangle or Circle). That means, you will use the concept of polymorphism.

Hint:

While building the list of shape objects, use rand(2) to generate a random number 0 or 1; if 0, then

you may add a Rectangle object, else add a Circle object to the list.

in ruby languageIn this task, your code creates a random list of 100 shape

Shape color "blue" Shape(color) radius 2.0 Circle(color, radius) Circle(radius) area() width 1.0, len 1.0 Rectangle(color, width, len) Rectangle(width, len) area() Circle Rectangle

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!