Given class Triangle, complete the program to read and set the base and height of triangle1 and triangle2, determine which triangle's area is larger, and output the larger triangle's info, making use of Triangle's relevant methods. class Triangle: def __init__(self): self.base = 0 self.height = 0 def set_base(self, user_base): self.base = user_base def set_height(self, user_height): self.height = user_height def get_area(self): area = 0.5 * self.base * self.height return area def print_info(self): print('Base: {:.2f}'.format(self.base)) print('Height: {:.2f}'.format(self.height)) print('Area: {:.2f}'.format(self.get_area())) if __name__ == "__main__": triangle1 = Triangle() triangle2 = Triangle() # TODO: Read and set base and height for triangle1 (use set_base() and set_height()) # TODO: Read and set base and height for triangle2 (use set_base() and set_height()) # TODO: Determine larger triangle (use get_area()) print('Triangle with larger area:') # TODO: Output larger triangle's info (use print_info())

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

Given class Triangle, complete the program to read and set the base and height of triangle1 and triangle2, determine which triangle's area is larger, and output the larger triangle's info, making use of Triangle's relevant methods.

class Triangle:
def __init__(self):
self.base = 0
self.height = 0

def set_base(self, user_base):
self.base = user_base

def set_height(self, user_height):
self.height = user_height

def get_area(self):
area = 0.5 * self.base * self.height
return area

def print_info(self):
print('Base: {:.2f}'.format(self.base))
print('Height: {:.2f}'.format(self.height))
print('Area: {:.2f}'.format(self.get_area()))

if __name__ == "__main__":
triangle1 = Triangle()
triangle2 = Triangle()

# TODO: Read and set base and height for triangle1 (use set_base() and set_height())

# TODO: Read and set base and height for triangle2 (use set_base() and set_height())

# TODO: Determine larger triangle (use get_area())

print('Triangle with larger area:')
# TODO: Output larger triangle's info (use print_info())

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,