Homework #1: Polymorphism In reference to the polymorphism example discussed in the class, you are required...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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). 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).
Expert Answer:
Answer rating: 100% (QA)
Code With Polymorphism abstract class Shape abstract double getArea class Square extends Shape doubl... View the full answer
Posted Date:
Students also viewed these computer network questions
-
Write a code that includes CSS and html to create a web page, provided that the page has two interfaces.
-
9. Suppose we are solving for Arb with A E Rmxn being rank deficient (minimum norm solution) (a) For b(A) why wouldn't the solution (ATA)-Ab work? (b) Suppose beR(A). Show that the error vector is...
-
For blood circulation in a specific human body artery, the following data is given, Average inner diameter of the artery = 6.8 mm Average pressure gradient per meter of length = 75 pa 1- Find the...
-
Which of the following is not true regarding the receivables turnover ratio? 1) It is used to assess the liquidity of receivables. 2) It has a popular variant called the average collection period. 3)...
-
Refer to Problem 4-6A. Before completing the steps, enter the unadjusted trial balance on an end-of-period spreadsheet (work sheet) and complete the spreadsheet. Add the accounts listed in...
-
Round Tree Manor is a hotel that provides two types of rooms with three rental classes: Super Saver, Deluxe, and Business. The profit per night for each type of room and rental class is as follows:...
-
The induced emf in an inductor of inductance \(L\) varies with time according to \(\mathscr{E}_{\text {ind }}(t)=-2 C t\), where \(C\) is a positive constant. (a) If there is no current through the...
-
Weighted-average method, spoilage, equivalent units. (CMA, adapted) Consider the following data for November 2009 from Gray Manufacturing Company, which makes silk pennants and uses a process-costing...
-
4. The atomic numbers of elements, U, V, W and X are 13, 14, 16 and 17 respectively. Which one of the elements will react with oxygen to form an ionic compound? (Atomic number of oxygen is 8) X A. B....
-
A gas containing 50 mol% propylene in propane is to be separated with silica gel having the equilibrium properties shown in Figure. The final products are to be 90 mol% propylene and 75 mol% propane....
-
For this assignment you will examine three primary source documents from the British colonial period in North America, and then write a one-paragraph journal entry explaining the similarities and...
-
Why would it be inappropriate for a custom-home builder to use process costing?
-
What are the four major stress and health theories, and how are they different?
-
How do maladaptive mental health conditions manifest as a consequence of stressors at work?
-
How is worklife conflict different from worklife enrichment?
-
What do you think organizations can do to mitigate the micro-stressors that commonly affect employees?
-
Charts of common variables from this class and constants from this class and other physics courses and their units are below. These will be used for problems 3-6. Some SI units are derived units that...
-
Chicago Company sold merchandise to a customer for $1,500 cash in a state with a 6% sales tax rate. The total amount of cash collected from the customer was $558. $600. $642. $636. Nevada Company...
-
Victoria has prepared the following list of statements about corporations. 1. A corporation is an entity separate and distinct from its owners. 2. As a legal entity, a corporation has most of the...
-
Indicate whether the following items would appear on the income statement (IS), statement of financial position (SFP), or retained earnings statement (RES). a. Dividends. b. Cash. c. Salaries and...
-
Victoria has studied the information you gave her in that exercise and has come to you with more statements about corporations. 1. Corporation management is both an advantage and a disadvantage of a...
Study smarter with the SolutionInn App