Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class named Triangle that extends Geometricobject. The class contains:

ID: 3774500 • Letter: D

Question

Design a class named Triangle that extends Geometricobject. The class contains: Three double data fields named side1, side2, and side3 with default values 1, 0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle. A constructor that creates a triangle with the specified side1, side2, and side3. The accessor methods for all three data fields. 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 tostring () that returns a string description for the triangle. For the formula to compute the area of a triangle, see Programming Exercise 2.19. The tostring () method is implemented as follows: return "Triangle: side1 = " + side1 +" side2 = " + side2 + " side3 = "+ side3; Draw the UML diagrams for the classes Triangle and Geometricobject and implement the classes. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input. The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not.

Explanation / Answer

class Triangle(GeometricObject):

def __init__(self):

self.side1 = 1.0

  self.side2 = 1.0

  self.side3 = 1.0

self.side = (self.side1 + self.side2 + self.self3) / 2 #semi- perimeter

def getArea(self):

s = self.side

#using heron's formula for area

area = (s * (s-a) * (s-b) * (s-c) ) ^ (0.5)

return area

def getPerimeter(self):

s = self.side

return 2*s #2*s is the perimeter

def toString(self):

return "Triangle : side1= "+self.side1+" side2= "+self.side2+" side3= "+self.side3

a = Triangle()

print a.getArea()

print a.getPerimeter()

print a.toString()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote