Question: Instructions You will need to create four files: Shape2D.py- file containing a class definition containing properties all Shapes could possibly have. Circle.py- file containing a

Instructions

You will need to create four files:

  • Shape2D.py- file containing a class definition containing properties all Shapes could possibly have.
  • Circle.py- file containing a class definition of a Circle that inherits from theShape2Dclass.
  • Square.py- file containing a class definition of a Square that inherits from theShape2Dclass.
  • testFile.py- file containing pytest functions testing theShape2D,Circle, andSquareclasses.

There will be no starter code for this assignment, but rather the class descriptions and required methods are defined in the specification below.

It's recommended that you organize your lab work in its own directory. This way all files for a lab are located in a single folder. Also, this will be easy to import various files into your code using theimport / fromtechnique shown in lecture.

Shape2D.pyclass

TheShape2D.pyfile will contain the definition of what a general 2D Shape is.

We will define this class' attributes as follows:

  • color-strthat represents the color of the shape.

You should write a constructor that allows the user to construct aShape2Dobject by passing in values for all the fields. You may assume calls to the constructor will always contain astrrepresenting the 2D Shape's color.

  • __init__(self, color)

In addition to your constructor, your class definition should also support "setter" and "getter" methods that can update and retrieve the state of the Shape2D objects:

  • setColor(self, color)- updates the color of the 2D Shape
  • getColor(self)- returns the color of the 2D Shape

Each 2D Shape object should be able to call a methodgetShapeProperties(self)that you will implement, which returns astrwith minimal 2D Shape information. Since a 2D Shape can be many things, the following output represents what will happen if we call thegetShapePropertiesmethod after constructing aShape2Dobject:

s1 = Shape2D("blue") print(s1.getShapeProperties()) 

Output:

Shape: N/A, Color: blue

Note:Thes1.getShapeProperties()return value in the example above does not contain a newline character ( ) at the end.

Circle.py

TheCircle.pyfile will contain the definition of what a 2D Circle will have. Since a CircleIS-A2D Shape, we will inherit the values we defined in theShape2Dclass. Since this lab focuses on inheritance, it is important thatyou only provide the method definitions below(you will not receive full credit if you implement other methods in theCircleclass definition, even if Gradescope's tests pass).

YourCircleclass definition should support the following constructor / methods:

  • __init__(self, color, radius)- Constructor that calls the parent class' (Shape2D) constructor and sets the radius parameter as an attribute to theCircleclass.
  • getRadius(self)- method that returns the radius value of the circle
  • setRadius(self, radius)- method that updates the value for the circle's radius
  • computeArea(self)- method that returns the area of the circle. You may use the following approximation of pi:3.14159
  • computePerimeter(self)- method that returns the perimeter of the circle. You may use the following approximation of pi:3.14159
  • getShapeProperties(self)- method that overrides the inheritedgetShapePropertiesmethod in theShape2Dclass, and returns astrwith the properties of aCircle. An example output for this method is as follows:
c1 = Circle("blue", 2.5) print(c1.getShapeProperties()) 

Output:

Shape: CIRCLE, Color: blue, Radius: 2.5, Area: 19.6349375, Perimeter: 15.70795

Note:Thec1.getShapeProperties()return value in the example above does not contain a newline character ( ) at the end.

Square.py

TheSquare.pyfile will contain the definition of what a 2D Square will have. Since a SquareIS-A2D Shape, we will inherit the values we defined in theShape2Dclass. Since this lab focuses on inheritance, it is important thatyou only provide the method definitions below(you will not receive full credit if you implement other methods in theSquareclass definition, even if Gradescope's tests pass).

YourSquareclass definition should support the following constructor / methods:

  • __init__(self, color, side)- Constructor that calls the parent class' (Shape2D) constructor and sets the side parameter of the square as an attribute to theSquareclass.
  • getSide(self)- method that returns the side value of the square
  • setSide(self, side)- method that updates the value for the square's side
  • computeArea(self)- method that returns the area of the square
  • computePerimeter(self)- method that returns the perimeter of the square.
  • getShapeProperties(self)- method that overrides the inheritedgetShapePropertiesmethod in theShape2Dclass, and returns astrwith the properties of aSquare. An example output for this method is as follows:
s1 = Square("blue", 2.5) print(s1.getShapeProperties()) 

Output:

Shape: SQUARE, Color: blue, Side: 2.5, Area: 6.25, Perimeter: 10.0

Note:Thes1.getShapeProperties()return value in the example above does not contain a newline character ( ) at the end.

testFile.pypytests

This file will contain unit tests using pytest to test if your functionality is correct. Think of various scenarios and method calls to be certain that the state of your objects and return values are correct (provide enough tests such that all method calls inShape2D,Circle, andSquareare covered).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!