Question: 4. To compute the triangle area, ensure that all side lengths are positive and the sum of any two side lengths is greater than the


4. To compute the triangle area, ensure that all side lengths are positive and the sum of any two side lengths is greater than the third side length. 5. The program should automatically create 3 Triangle and 3 Square objects and print out all their properties. For example, the program would return the following output upon execution: Square Sides: [2] Area: 4 Triangle Sides: [7, 2, 9] Area: 0.0 Square Sides: [6] Area: 36 Triangle Sides: [9, 8, 6] Area: 23.53 Square Sides: [7] Area: 49 Triangle Define four classes, Polygon , Rectangle , Square ,and Triangle . Polygon is the parent class of Rectangle , which is the parent class of Square . Polygon also is the parent class of the Triangle class. This figure might be helpful to visualize the hierarchy of these classes. 1. The Polygon should have the following methods: - A method called WhoAmI that prints out Triangle if the current object is a triangle or Square if the current object is a square. - A method called side_lengths to print the side lengths of the polygon. o A method called findArea() that can be overridden to compute and return the Polygon area. 2. When creating Rectangle objects, the program should generate two random integers as the sides of the rectangle. Similarly, the program should randomly generate one random integer denoting one side for' Square' objects. The side lengths can be any value between 1 and 10, inclusively. 3. Each of the Rectangle , Triangle and Square classes should have a method called findArea() that computes and returns the respective area according to the following formulae: SquareArea = side2 RectangleArea = side] X side; TriangleArea = 1/p(p side1)(p side2)(p side3), where p = W
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
