Page 1 of 1

Question 2 GoWhere is a private car ride company that offers two types of travel cards to customers: 1) trip travel card

Posted: Mon May 09, 2022 1:34 pm
by answerhappygod
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 1
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 1 (165.71 KiB) Viewed 40 times
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 2
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 2 (199.63 KiB) Viewed 40 times
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 3
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 3 (177 KiB) Viewed 40 times
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 4
Question 2 Gowhere Is A Private Car Ride Company That Offers Two Types Of Travel Cards To Customers 1 Trip Travel Card 4 (117.48 KiB) Viewed 40 times
PLEASE ANSWER PART A & B
python OOP
THANK YOU
Please answer part A to C
using Python OOP
thank you
Question 2 GoWhere is a private car ride company that offers two types of travel cards to customers: 1) trip travel card where a customer gets one long (more than 12 km) trip and 3 short trips, and 2) distance travel card that gives customers as many trips as long as the accumulated distance is not more than 50 km. Travel cards have expiry dates and can be topped up as long as they have not expired. Trip _tripDate: datetime _startPoint:str _destination:str _distance:float _driver:Driver _init_(self, tripDate, startPoint, destination, distance, driver) tripDate(self):datetime distance(self):float driver (self):Driver driverName(self):str _str_(self):str TravelCard {abstract) _cardNo:str _expiry Date: date _trips:list _init__(self,card No, expiry Date) card No(self):str expiryDate(self):datetime getTripDriverByTripNumber(self, number):Driver getTripByDate(self, aDate):list addTrip(self, trip):bool canTravel(self, distance):bool (abstract) consumeDistance(self, distance):bool (abstract) top Up(self) (abstract} balance Detail(self):str(abstract) str_(self):str 4 Trip TravelCard Distance TravelCard Driver _nextid: Int _driverld:int _name:str _contact:str _init__(self,name, contact) driverld(self):int name(self):str contact(self):str contact(self, newContact) _str_(self):str short DistanceMaxLimit: int=12 topUpLongShort Trips:list=[1, 3] _long Trip:int _short Trip:int _init__(self,card No, expiry Date) can Travel(self, distance):bool consumeDistance(self, distance):bool top Up(self) balance Detail(self):str Figure Q2 topUp Distance:int=50 distanceLeft:float _init__(self,card No, expiry Date) canTravel(self, distance): bool consumeDistance(self, distance):bool topUp(self) balance Detail(self):Str Study the class diagram in Figure Q2. The TravelCard class, the TripTravelCard class, and the Distance TravelCard class are described in Table Q2(a) to Table Q2(c) respectively. You will implement only the TravelCard and TripTravelCard classes.
The TravelCard class is an abstract class. It has the following attributes: _cardNo records the card number _expiry Date records the expiry date of the travel card _trips records a list of trips taken using the travel card The TravelCard class has the following methods: _init_(self, cardNo, expiryDate) initialises a new travel card with the parameters cardNo and expiry Date, and set_trips as an empty list. Getter methods for cardNo and expiryDate. getTripDriverByTrip Number(self, n):Driver returns the driver of the n-th trip. If n is î, the driver of the first trip in the list is returned, if n is 2, the driver of the second trip is returned, and so on. Return None ifn is zero or negative or if the n-th trip does not exist. getTripByDate(self, aDate):list returns a list of trips taken on aDate. The method returns None if no trip is taken on aDate. addTrip(self, trip):bool returns True if the trip can be added to _trips. A trip can be added under the condition that the expiry date of the travel card is on or after the date of the trip, and the travel card has sufficient balance to make the trip, as determined by the method canTravel(self, distance). If the condition is satisfied, the trip can be added to _trips, and the method deducts from the balance of the card by calling the method consumeDistance(self, distance). An abstract method canTravel(self, distance):bool. An abstract method consumeDistance(self, distance):bool An abstract method topUp(self). An abstract method balance Detail(self):str str_(self) returns a string representation of a card, including the balance details of the card(shown in bold, dependent on the type of travel card) and its trips. Three example strings are shown here: Card Number:C123 Expiry Date: 30 Jun 2021 Remaining Long trips: Short trips: 1 30 May 2020, 12:35 From: Parkway Parade To: Tampines Mall Distance: 11.0km Driver Id: 2 Name Tom Contact: 88998899 30 May 2020, 17:45 From: Tampines Mall To: Parkway Parade Distance: 11.2km Driver Id: 1 Name John Contact: 98989898 04 Jun 2020, 12:35 From: Jurong Point To: Parkway Parade Distance: 20.3km Driver Id: 2 Name Tom Contact: 88998899 Card Number:C003 Expiry Date: 01 Jan 2020 Remaining Long trips: 1 Short trips: 3 No trips yet Card Number:0901 Expiry Date: 01 Jan 2022 Remaining Distance: 29.7km 05 Jun 2020, 08:30 From: Jurong Point To: Parkway Parade Distance: 20.3km Driver Id: 2 Name Tom Contact: 88998899 Table Q2(a)
The TripTravelCard class is a subclass of the TravelCard class. It has the following attributes in addition to the attributes of the TravelCard class: shortDistanceMaxLimit is 12 km or the distance a short trip cannot exceed. Any trip with a distance greater than 12 km is a long trip. topUpLongShortTrips is a list of 2 items, 1 and 3, the number of the long trips and short trips respectively, that a trip travel card has when initialised. The numbers in topUpLongShortTrips are also used to add to the long trips and short trips when a trip travel card is topped up. _longTrip records the number of long trips remaining for a trip travel card. _longTrip is initially set to the first item in _topUpLongShort Trips. _shortTrip records the number of short trips remaining for a trip travel card. shortTrip is initially set to the second item in _topUpLongShort Trips. The TripTravelCard class has the following methods, in addition to the methods of the TravelCard class: _init_(self, cardNo, expiryDate) which also initialises _long Trip and _shortTrip with the items in the list, _topUpLongShortTrips. can Travel(self, distance):bool returns True if the card has sufficient balance for the distance, that is, the distance is short and _shortTrip is positive. the distance is short but although shortTrip is zero, _longTrip is positive. One long trip can be converted to two short trips, one of which can be used for the short distance. the distance is long and _longTrip is positive. the distance is long but although_longTrip is zero, _shortTrip is at least 3. Three short trips can be converted to one long trip which can then be used for the long distance. The method returns False if the trip travel card does not have enough long and short trips for the distance. consumeDistance(self, distance):bool returns True when trip travel card can be used for the distance, and the card balance is successfully deducted, with remaining trips converted from long to short or vice versa, if necessary. topUp(self) adds to long and short trips, according to the numbers in the list, topUpLongShortTrips. balance Detail(self):str returns a string representation for the remaining trips. An example string is shown here: Long trips: 1 Short trips: 3 Table Q2(b)
The Distance TravelCard class is a subclass of the TravelCard class. It has the following attributes in addition to the attributes of the TravelCard class: topUp Distance is 50 km which is the distance left a distance travel card has when initialised, and amount to add to the distance left when a distance travel card is topped up. _distanceLeft records the remaining distance that a distance travel card has. The Distance TravelCard class has the following methods, in addition to the methods of the TravelCard class: init__(self,cardNo, expiry Date) which also initialises distance Left with_topUpDistance. canTravel(self, distance):bool returns True if the distance left in the card is at least the parameter distance. The method returns False otherwise. consumeDistance(self, distance):bool returns True when trip travel card can be used for the distance, and the card balance is successfully deducted. topUp(self) adds _topUpDistance to the distance left in the distance travel card. balance Detail(self):str returns a string representation for the remaining distance. An example string is shown here: Distance: 29.7km Table 02(c) Demonstrate your understanding of how class hierarchy and association are used to organize information, and then construct the class hierarchy and association according to specification. (a) Define the TravelCard class. (15 marks) (b) Define the Trip TravelCard class. (15 marks)