Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Code With Polymorphism abstract class Shape abstract double getArea class Square extends Shape doubl...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