Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON Question IV: Design a class named Triangle that extends the GeometricObject class given in the textbook. The Triangle class contains: - Three float

IN PYTHON

Question IV: Design a class named Triangle that extends the GeometricObject class given in the textbook. The Triangle class contains: - Three float data fields named side1, side2, and side3 to denote the three sides of the triangle. - A constructor that creates a triangle with the specified side1, side2, and side3 with default values 1.0. - The accessor (getter) and mutator (setter) methods for all three data fields. - The class should throw a RuntimeError exception if the three given sides cannot form a triangle (If one of sides is 0 or less than 0.) - A method named getArea() that returns the area of this triangle. - A method named getPerimeter() that returns the perimeter of this triangle. - A method named __eq__(self, other) that checks whether two triangles are equal of not by comparing their three sides. For example, if a triangle has side lengths 4,1,3 and another one has side lengths 3,4,1 then they should be accepted equal. - A method named __str__() that returns a string description for the triangle. The __str__() method is implemented as follows: return "Triangle: side1 = " + str(side1) + " side2 = " + str(side2) + " side3 = " + str(side3) Implement the Triangle class. Write a test program that generates triangles with three sides of the triangle, a color, and 1 or 0 to indicate whether the triangle is filled. The program should generate three Triangle objects. Two of these triangles should have the same side lengths. The program should display triangles area, perimeter, color, and True or False to indicate whether the triangle is filled or not. The program should also compare triangles with each other whether they are equal or not.image text in transcribed

Question IV: Design a class named Triangle that extends the Geometricobject class given in the textbook. The Triangle class contains: Three float data fields named side1, side2, and side to denote the three sides of the triangle. A constructor that creates a triangle with the specified side1, side2, and sides with default values 1.0. The accessor (getter) and mutator (setter) methods for all three data fields. The class should throw a RuntimeError exception if the three given sides cannot form a triangle (If one of sides is 0 or less than 0.) A method named getArea() that returns the area of this triangle. A method named getPerimeter() that returns the perimeter of this triangle. A method named_eq_(self, other) that checks whether two triangles are equal of not by comparing their three sides. For example, if a triangle has side lengths 4,1,3 and another one has side lengths 3,4,1 then they should be accepted equal. A method named _str_() that returns a string description for the triangle. The_str_() method is implemented as follows: return "Triangle: side1 = " + str(sidel) +" side2 =" + str(side2) + " side3 = " + str(side3) Implement the Triangle class. Write a test program that generates triangles with three sides of the triangle, a color, and 1 or o to indicate whether the triangle is filled. The program should generate three Triangle objects. Two of these triangles should have the same side lengths. The program should display triangle's area, perimeter, color, and True or False to indicate whether the triangle is filled or not. The program should also compare triangles with each other whether they are equal or not

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions