For this assignment you will use Blackboard to submit a single .py file containing solutions to the following programming exercises. Your file should have header comments that include your name, the date, and your acknowledgments statement. Carefully test each function to make sure that it works as expected. These exercises will be graded both on functionality and code quality.
contains
method should return True when the tested point
is contained in the shape or touching the boundary.
contains
method for
the polygon class. You need not fully implement that
method. Instead, it should raise an exception of
type NotImplementedError
.
def testShapeClasses(): rect = Rectangle(0., 200., 50., 100., "blue") circ = Circle(0., 200., 40., "red") tri = Polygon(0., 200., 3, 40.,"black") print("Testing Accessor Methods-------------------------------------------") print("Rectangle, should see: 0., 200., 50, 100., blue") print("{0} {1} {2} {3} {4}".format(rect.xPos(), rect.yPos(), rect.height(), rect.width(), rect.color())) print("Circle, should see: 0., 200., 40, red") print("{0} {1} {2} {3}".format(circ.xPos(), circ.yPos(), circ.radius(), circ.color())) print("Polygon, should see: 0., 200., 3, 40., black") print("{0} {1} {2} {3} {4}".format(tri.xPos(), tri.yPos(), tri.numSides(), tri.sideLength(), tri.color())) print("\nTesting Contains Methods-----------------------------------------") print("(0,0) should not be in rectangle (False):") print(rect.contains(0.,0.)) print("(20,210) should be in rectangle (True):") print(rect.contains(20.,210.)) print("(0,0) should not be in circle (False):") print(circ.contains(0.,0.)) print("(0,200) should be in circle (True):") print(circ.contains(0.,200.)) try: tri.contains(0., 0.) print ("ERROR, exception should have been raised.") except NotImplementedError: print ("Polygon contains NotImplemented exception successfully raised.") print("\nTesting __str__ methods, should display three shapes as strings:-----") print(rect) print(circ) print(tri) print("\nTesting draw methods---------------------------------------------") rect.draw() circ.draw() tri.draw() turtle.exitonclick()The result of the draw commands should look something like the following:
drawPolygons
function from HW#2
to drawShapes
and rewrite it so that it takes a
list of Shape objects as an argument. (The code should be
simpler than the previous version.) Don't forget to update
the docstring appropriately. List the preconditions for
this function and use assertions to test them. (5pts)
readShapeFile
that takes a
filename as an argument, and returns a list of shapes. Each line in a correctly formatted file will specify a single shape object:
r 0.0 200.0 50.0 100.0 blue c 0.0 200.0 40.0 red p 0.0 200.0 3 40.0 blackAlso, create a user-defined exception class named
FileFormatError
. Your new function should raise
a FileFormatError
if the file format is not
correct. (5pts)