In this assignment, you'll create a program that combines modules and classes. The classes will be created in separate files, shape.py and circle.py.Python Programming

1.  Reading and Study

Week 4's's's reading

How to write code to test your modules Before you start writing your program:

Study and understand the Shape class described on page 33.

Study and understand the Circle class described on in section 15.5.2 (p. 215).

super()

Lab files

Download The Shape and Circle modules designed for this assignment. These modules are modifications of the Circle and Shape classes shown in The Quick Python Book/These two files have a /.txt file extension that you'll have to remove to make them .py files.

In this assignment, you'll create a program names lab4.1.py that combines modules and classes. The classes will be created in separate files, shape.py and circle.py. To complete this problem you will be writing several methods in the shape.py and circle.py.

The final exam will contain a question about classes and modules

When you write lab4.1.py, you will import the Shape and Circle classes into your program. Your lab4.1.py program will generate plain text output that is organized and readable by the grader (me!).

Summary

lab4.1.py uses two classes, Shape and Circle. The Circle class is a subclass of
Shape.
The shape.py file is a module that contains the Shape class, the parent class of geometric shapes such as Circle.
The circle.py file is a module that contains the Circle class, which is a subclass of
Shape. As a subclass, Circle must import shape.py.

lab4.1.py will:

Import the shape.py and circle.py modules. Create two Circle objects.
Move the two circle objects around the x,y co-ordinate system by changing their x and y
coordinates.
Determine whether the circles overlap, or "collide" with each other. "Collide", in this assignments, means that the two circles occupy the same point at the same time. That is to say, if the two circles intersect, they are colliding. This faux animated example will help you visualize how your script will generate a series of circles and report whether they are colliding. This example is really a series of HTTP requests, one for each movement of the two circles.

Example output

Your script should display your program's data as well-formatted, readable, human-friendly plain text, as in the plain text example below. If you're feeling ambitious, you might want to try writing a CGI script that will format the output using HTML.

Your script should create plain text output.

Plain text output of lab4.1.py

TODO Complete the shape.py module

Download shape.py

The Shape class in shape.py is almost complete. The location() method needs to be completed. You'll see it indicated like this.

########################################## # TODO TODO TODO --- COMPLETE THIS METHOD ##########################################

def location(self):

'''Returns a tuple containing the (x,y) coordinates of a Shape object

When writing your code, you have to replace "pass" with your code.''' pass

init (), a class constructor what sets an objects x,y coordinates. Completed

move(), a method to move objects to new x,y coordinates. Completed                                                                                       

location(), a method that returns a tuple containing an object x,y coordinates. You have to complete this method. This method will be inherited by any subclasses.

The Shape class provides methods to set a shape's x,y coordinates, to move the shape to a new set of coordinates, and to report the shape's location as a tuple containing the object's x,y coordinates. You have to complete the location() method.

Here's some code to get you started on shape.py. It's based on the source code for the Shape

class on p. 30 of The Quick Python Book.

Attachments:

Instructions Files

Python Programming Experts

expert
Oliver
Python Programming

60 Answers

expert
Issac Torres
Python Programming

67 Answers

View More Experts
Disclaimer

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

258 Experts Online