Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following python Exercise: Here is some code to help you. #Listing 12.1 GeometricObject.py class GeometricObject: def __init__(self, color = green, filled = True):

Consider the following python Exercise:

image text in transcribed

Here is some code to help you.

#Listing 12.1 GeometricObject.py class GeometricObject: def __init__(self, color = "green", filled = True): self.__color = color self.__filled = filled def getColor(self): return self.__color def setColor(self, color): self.__color = color def isFilled(self): return self.__filled def setFilled(self, filled): self.__filled = filled def __str__(self): return "color: " + self.__color + \ " and filled: " + str(self.__filled) #-------------------------------------------------------------- #Listing 12.2 CircleFromGeometricObject.py from GeometricObject import GeometricObject import math class Circle(GeometricObject): def __init__(self, radius): super().__init__() self.__radius = radius def getRadius(self): return self.__radius def setRadius(self, radius): self.__radius = radius def getArea(self): return self.__radius * self.__radius * math.pi def getDiameter(self): return 2 * self.__radius def getPerimeter(self): return 2 * self.__radius * math.pi def printCircle(self): print(self.__str__() + " radius: " + str(self.__radius)) #-------------------------------------------------------------- #Listing 12.3 RectangleFromGeometricObject.py from GeometricObject import GeometricObject class Rectangle(GeometricObject): def __init__(self, width = 1, height = 1): super().__init__() self.__width = width self.__height = height def getWidth(self): return self.__width def setWidth(self, width): self.__width = width def getHeight(self): return self.__height def setHeight(self, height): self.__height = self.__height def getArea(self): return self.__width * self.__height def getPerimeter(self): return 2 * (self.__width + self.__height) #-------------------------------------------------------------- #LiveExample 12.4 TestCircleRectangle.py from CircleFromGeometricObject import Circle from RectangleFromGeometricObject import Rectangle def main(): circle = Circle(1.5) # Create a Circle with radius 1.5 print("A circle", circle) print("The radius is", circle.getRadius()) print("The area is", circle.getArea()) print("The diameter is", circle.getDiameter()) rectangle = Rectangle(2, 4) print(" A rectangle", rectangle) print("The area is", rectangle.getArea()) print("The perimeter is", rectangle.getPerimeter()) main() # Call the main function 

(The Triangle class) Design a class named Triangle that extends the GeometricObject class. 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 side with default values 1.0. - 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_str_ that returns a string description for the triangle. For the formula to compute the area of a triangle, see Exercise 2.14. The_str__() method is implemented as follows: return "Triangle: side1 = " + str(side1) + " side2 = " + str(side2) + " side3 = " + str(side3) Draw the UML diagrams for the classes Triangle and Geometricobject Implement the Triangle class. Write a test program that prompts the user to enter the three sides of the triangle, a color, and 1 or 0 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 triangle's area, perimeter, color, and True or False to indicate whether the triangle is filled or not. Sample Run Enter side1: 2.5 Enter side2: 3.1 Enter side3: 2.8 Enter color: red Enter 1/0 for filled (1: true, : false): 1 The area is 3.3159613990515604 The perimeter is 8.399999999999999 Color is red Filled is True

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions