Question

Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in#This program defines the geometric object class. # (It is in a file named GeometricObjectClass) def getArea(self) return sel

Python only please, thanks in advance.

Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default values 4 and 2, respectively The accessor methods for both data fields A method named getArea() that returns the area of the rectangle .A method named getPerimeter(0 that returns the perimeter of the rectangle e A method namedstr_0 that returns a string description of the rectangle (length and width) Write a test program (named TestRectangle , placing it in your folder) that prompts the user to enter the length and width of the rectangle, a color and 1 or 0 to indicate whether the rectangle is filled. The program should create a Rectangle object with these measurements and set the color and filled properties using the input. The program should display the rectangle's area, perimeter, color and True or False to indicate whether the rectangle is filled or not. 3. 4. Include exception handling in the TestRectangle program to take care of the entry of negative numbers or of strings instead of numbers
#This program defines the geometric object class. # (It is in a file named GeometricObjectClass) def getArea(self) return self.radius * self.radius math.pi class GeometricObject: init (self, color "green", filled-True): def getDiameter(self) return 2 radius def self.color color self.filled filled def getPerimeter(self) return 2 * math.pi *self.radius def getColor(self) return self.color def_ str_(self) return "circle with radius " + str(self.radius)n"+super) str_0 def setcolor(self, color) self.color color #This program uses the circle class. It is missing the try/except from CircleClass import Circle def main() def isFilled(self) return self.filled def setFilled(self, filled) self.filled filled filled eval(input!"Type 1 for filled and 0 for not filled: ")) color input("Type the circle color:") radius - eval(linputf"What is the radius of the circle? ") def_str_(self) return "color: " + self.color"and filled:"+ str(self.filled) circle Circle(radius) if filled1: #This is the circle class as a subclass of the geometric object class # (It is in a file named CircleClass) circle.setFilled (True) else circle.setFilled(False) circle.setColor(color) circle.setRadius(radius) from GeometricObjectClass import GeometricObject import math class Circle(GeometricObject) def_init_(self, radius) super().-init-L) self.radius radius print(circle) print() print"The area of the circle is"+ strfcircle.getAreal() printf"The perimeter is"+str(circle.getPerimeter) def getRadius(self) return self.radius main() def setRadius(self, radius) self.radius radius
0 0
Add a comment Improve this question Transcribed image text
Answer #1
GeometricObjectClass.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)
RectangleClass.py

from GeometricObjectClass import GeometricObject

class Rectangle(GeometricObject):
   def __init__(self, length, width):
      super().__init__()
      self.length = length
      self.width = width
   def getLength(self):
      return self.length
   def setLength(self, length):
      self.length = length

   def getWidth(self):
      return self.width
   def setWidth(self, width):
      self.width = width

   def getArea(self):
      return self.length * self.width

   def getPerimeter(self):
      return 2 * (self.length + self.width)

   def __str__(self):
      return  "rectangle with length:"+ str(self.length) +" and width:"+ str(self.width) 

TestRectangle.py
from RectangleClass import Rectangle

# method to check if number is digit using try/except
def is_value_digit(n):
   try:
      int(n)
      return True
   except ValueError:
      return  False

# method to get non negative number

def getNonNegativeIntegerInput(question):
   n = input(question)
   if is_value_digit(n) is True:
      if int(n)>0 :
         return int(n)
      else:
         print(n, "is negative enter positive value.")
         return getNonNegativeIntegerInput(question)
   else:
      print(n, "is not an integer.")
      return getNonNegativeIntegerInput(question)
def main():
   filled = eval(input("Type 1 for filled and 0 for not filled:"))
   color = input("Type the rectangle color:")

   width = getNonNegativeIntegerInput("Enter the width:")
   length = getNonNegativeIntegerInput("Enter the length:")
   rectangle = Rectangle(width, length)

   if filled == 1:
      rectangle.setFilled(True)
   else:
      rectangle.setFilled(False)
   rectangle.setColor(color)

   print(rectangle)
   print()
   print("Area of rectangle:" + str(rectangle.getArea()))
   print("Perimeter of rectangle:" + str(rectangle.getPerimeter()))
main()

SAMPLE output screenshot:

$ python TestRectangle.py Type 1 for filled and 0 for not filled: 1 Type the rectangle color:red Enter the width: 3 Enter the

Add a comment
Know the answer?
Add Answer to:
Type up the GeometricObject class (code given on the back of the paper). Name this file Geometric...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python only please, thanks in advance. Type up the GeometricObject class (code given on the back...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • Design a general class GeometricObject can be used to model all geometric objects. This class contains...

    Design a general class GeometricObject can be used to model all geometric objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object. Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class. The Triangle class inherits all accessible data fields and methods from the GeometricObject class.In addition, it has three double data fields named...

  • (The Triangle class) Design a class named Triangle that extends the GeometricObject class. The Triangle class...

    (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 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 methods for all three data fields. - A method named getArea() that returns the area of this triangle. - A method named getPerimeter() that...

  • Introduction to Java:Design a class named Triangle that extends GeometricObject.

    Please include comments in the program .The program must be able to be compiled.Design a class named Triangle that extends GeometricObject. This class contains:* Three double data fields named side1, side2, and side3 with default values 1.0 to denote the three sides of a 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...

  • Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields...

    Design a class named Triangle that extends GeometricObject class. 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 with color = "blue", filled = true. A constructor that creates a triangle with the specified side1, side2, side3 and color = "blue", filled = true. The accessor functions for all three data fields, named getSide1(), getSide2(), getSide3(). A function...

  • Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the...

    Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...

  • this is for java programming Please Use Comments I am not 100% sure if my code...

    this is for java programming Please Use Comments I am not 100% sure if my code needs work, this code is for the geometric if you feel like you need to edit it please do :) Problem Description: Modify the GeometricObject class to implement the Comparable interface and define a static max method in the GeometricObject class for finding the larger (in area) of two GeometricObject objects. Draw the UML and implement the new GeometricObject class and its two subclasses...

  • import math ''' Finish the code below as described. Use the completed class Square as an...

    import math ''' Finish the code below as described. Use the completed class Square as an example. ''' class Square: ''' Each Square has a width and can calculate its area, its perimeter, and return a string representation of itself. ''' def __init__(self, width): ''' (float) -> None Create a new Square with the given width. ''' self.width = width def get_area(self): ''' () -> float Return this square's area. ''' return self.width*self.width def get_perimeter(self): ''' () -> float Return...

  • write a completed program (included the main) for the Q: add an equals method to each...

    write a completed program (included the main) for the Q: add an equals method to each of the Rectangle circle and triangle classes introduced in this chapter. two shapes are considered equal if their fields have equivalent values. based on public class Circle implements Shape f private double radius; // Constructs a new circle with the given radius. public Circle (double radius) f this.radius - radius; // Returns the area of this circle. public double getArea) return Math.PI *radius *...

  • The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public...

    The software I use is Eclipse, please show how to write it, thanks. GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; protected GeometricObject() { dateCreated = new java.util.Date(); } protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public boolean isFilled() { return filled; } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT