Consider the following code to answer below questions: public double calculatePerimeter(Shapes [] shapes) { double p = 0; for (Shape shape : shapes) { if (shape is Rectangle) { Rectangle rectangle =...


Consider the following code to answer below questions:<br>public double calculatePerimeter(Shapes [] shapes)<br>{<br>double p = 0;<br>for (Shape shape : shapes)<br>{<br>if (shape is Rectangle)<br>{<br>Rectangle rectangle = (Rectangle) shape;<br>p += (rectangle.Width+rectangle.Height) * 2;<br>} else {<br>Circle circle = (Circle)shape;<br>p += 2 * circle.Radius * Math.PI;<br>}<br>}<br>return p;<br>}<br>1. which design principle is violated in the above code?<br>2. what is the issue/ limitation of this code?<br>3. rewrite the code to not violate the design principle you answered in part 1?<br>

Extracted text: Consider the following code to answer below questions: public double calculatePerimeter(Shapes [] shapes) { double p = 0; for (Shape shape : shapes) { if (shape is Rectangle) { Rectangle rectangle = (Rectangle) shape; p += (rectangle.Width+rectangle.Height) * 2; } else { Circle circle = (Circle)shape; p += 2 * circle.Radius * Math.PI; } } return p; } 1. which design principle is violated in the above code? 2. what is the issue/ limitation of this code? 3. rewrite the code to not violate the design principle you answered in part 1?

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here