Assignment A class «Trip» has been awarded. It is intended to meet all the requirements set forth below but contains some errors. The task is to write tests for this class and the next fix the...

1 answer below »
python


Assignment A class «Trip» has been awarded. It is intended to meet all the requirements set forth below but contains some errors. The task is to write tests for this class and the next fix the problems so that the class passes the tests. The "Trip" class uses the "Position" class, which is also distributed. A position has x-coordinate, y-coordinate and height. -A name that is a string. -A start time. Here you only need to use numbers for this exercise's part, but those who want can test the use of datetime objects from the datetime package. -An end time that cannot be the first start time. Here you can use numbers or datetime objects in the same way as for start time -A list of positions that show where the trip has gone. The trip class should have the following methods -A method add_position (position) that should add to a position specified as a position object. It should be added to the end of the list -A method add_position_coordinates (x_coordinate, y_coordinate, height) that should add to a position specified with x-coordinate, y- coordinate and height. You must create position objects of such positions before you add them to the list-A method is_tour () that asks if the trip is a round trip. A trip is a round trip if the first and last position are equal. Two positions are equal if they have the same coordinates and altitude. -A method altimeter () that calculates the total amount of altitude meters that you have walked. To calculate altitude meters, calculate the difference in height between two consecutive positions in the position list. Add up all these height differences and return it. Example values for altitude meter 1: Given a trip between four points (x = 2, y = 3, height = 2), (x = 20, y = 5, height = 20), (x = 18, y = 13, height = 22 ) and (x = 2, y = 3, height = 2) then the altimeter method should return 40. The difference between 2 and 20 is 18. The difference between 20 and 22 is 2. The difference between 22 and 2 is 20. 18 + 2 + 20 = 40. Note that this is a round trip since it starts and ends in the same place. Example values for altitude meter2: Given a trip between the following three points (x = 5, y = 3, altitude = 10), (x = 15, y = 5, height = 18), (x = 12, y = 15, height = 12) then the altimeter method should return 14. The difference between 10 and 18 is 8. The difference between 18 and 12 is 6. 8 + 6 = 14.I Unlike the previous trip, this is not a round trip since it starts and ends in different places. Sub-tasks a) Write unit tests for property end times and methods listed above. Make trips with the example values given above to test the "altimeter" and "is_roundtrip" methods. You can make several trips as well. The end-time test should check that you get an exception if you try to make a trip that ends before it starts. b) Use the unit tests from problem a) to find the errors in the distributed code c) Fix the errors so that the class works as intended.
Answered 3 days AfterApr 14, 2021

Answer To: Assignment A class «Trip» has been awarded. It is intended to meet all the requirements set forth...

Arun Shankar answered on Apr 18 2021
151 Votes
Files/Trip.py
import Position
class Trip:
def __init__(self, name, start_time, end_time):
if (start_time > end_time):
raise Exception("end_time_exception")
self.name = name
self.start_time = start_time
self.end_time = end_time
self.positions = list()
def add_position(self, position):
self.positions.append(position)

def add_position_coordinates (self, x_coordinate, y_coordinate, height):
self.positions.append(Position.Position(x_coordinate, y_coordinate, height))
def height_meter(self):
result = 0.0
for i in range (1, len(self.positions)):
result += self.positions[i-1].height_difference (self.positions[i])
return result
def er_rundtur(self):
if self.positions[0].__eq__(self.positions[-1]):
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here