Question: Homework #1: Polymorphism In reference to the polymorphism example discussed in the class, you are required to implement the example using JAVA or C++.

Homework #1: Polymorphism In reference to the polymorphism example discussed in the

Homework #1: Polymorphism In reference to the polymorphism example discussed in the class, you are required to implement the example using JAVA or C++. Please use the below diagram to implement your solution. Square -sideLength: double +getArea(): double Canvas 1 Shape +getArea(): double Circle -radius: double +getArea(): double The area of the square= sideLength * sideLength The area of the circle = 3.14 * radius * radius The are of the triangle = 0.5* base* height Triangle -base: double -height: double +getArea(): double To verify the correctness of your solution, you are required to implement the Canvas class, which includes an array of shapes. As in the solution discussed in class, you should iterate over the list of shapes and print their areas. In addition to the polymorphic solution, you should also submit another solution to implement the same problem without polymorphism (Do not use inheritance).

Step by Step Solution

3.50 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Code With Polymorphism abstract class Shape abstract double getArea class Square extends Shape doubl... View full answer

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 Computer Network Questions!