Project: Taxicab
Write a class called Taxicab with three private data members: the cab's
x-coordinate, its y-coordinate, and its odometer reading.
- The
__init__method takes two parameters, the starting x and y coordinates. It sets the odometer to zero. - There is a getter for each data member:
get_x_coord,get_y_coordandget_odometer. move_xtakes a number saying how far the cab moves left or right.move_ytakes a number saying how far the cab moves up or down.- The odometer adds up the distance travelled, so moving left counts the same as moving right.
Here is how the class could be used:
cab = Taxicab(3, -8) # creates a Taxicab object at coordinates (3, -8)
cab.move_x(4) # moves cab 4 units "right"
cab.move_y(-5) # moves cab 5 units "down"
cab.move_x(-2) # moves cab 2 units "left"
print(cab.get_odometer()) # prints the current odometer reading
Save the file as Taxicab.py.
Show a solution
Try the project on your own first. This is one working solution, followed by its tests. Press Run to run the tests. Read them to see what thorough testing looks like, then change the solution and run again to watch a test fail.
Projects run on your own computer, so you tell us when you are done.