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 language
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 RectangleStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started