Object Oriented Programming

User Generated

oryzbagsbb

Programming

Description

Question 1

A tour agency needs to track the tours it has scheduled, the bookings made for them and the passengers that the bookings are for.

Question 2

You are given the class Product that has a code and quantity on hand, the relevant getter and setter methods and the string method

class Product:

def __init__(self, code, qtyOnHand):

self._code = code

self._qtyOnHand = qtyOnHand

@property

def code(self):

return self._code

@property

def qtyOnHand(self):

return self._qtyOnHand

@qtyOnHand.setter

def qtyOnHand(self, qtyOnHand):

self._qtyOnHand = qtyOnHand

def __str__(self):

return 'Code: {:5s} Quantity: {:3d}'.format(self._code, self._qtyOnHand)


Question 3

Implement a simple graphical user interface (GUI) to simulate a cash register for a burger outlet which serves three types of burger. Burger Code

Name

Price

B

Beef Burger

12.95

C

Chicken Burger

5.95

F

Fish burger

7.95


Unformatted Attachment Preview

ICT162 Object Oriented Programming Tutor-Marked Assignment July 2018 Presentation ICT162 Tutor-Marked Assignment TUTOR-MARKED ASSIGNMENT (TMA) This assignment is worth 18 % of the final mark for ICT162, Object Oriented Programming. The cut-off date for this assignment is Thursday, 18 October 2018, 2355 hours. Note to Students: You are to include the following particulars in your submission: Course Code, Title of the TMA, SUSS PI No., Your Name, and Submission Date. Question 1 A tour agency needs to track the tours it has scheduled, the bookings made for them and the passengers that the bookings are for. (a) The tour agency organises tours. Test data for three tours is given in Table Q1.1 below: Tour Code Tour Name JA312 KO111 VI102 Food Trail in Toyko Discover Korea Vietnam Highlights Number of Days 7 8 5 Number of Nights 6 7 4 Cost($) 1999.14 1449.36 999.75 Table Q1.1 Implement the class Tour which has i) the instance variables for the following pieces of data:  a tour code,  a tour name,  number of days and nights and  the cost of the tour. ii)    methods: Getter methods for the tour code, number of days and cost. Use the property decorator. Setter method for cost. Use the setter decorator. A string method that returns all its attributes. Here is an example in the required format: Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 (4 marks) SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 2 of 22 ICT162 (b) Tutor-Marked Assignment The tour agency schedules tours to depart during peak or normal period. Test data for five scheduled tours is given in Table Q1.2 below: Type of Schedul e Normal Peak Scheduled for Tour with tour code JA312 Schedul e Code Language Departure Date and time Capacity Available Seats Is Open 1 English 35 9 no JA312 2 25 25 yes VI102 5 Mandari n English 35 35 yes KO111 6 50 45 yes KO111 2 5 Nov 2018 3.30 pm 15 Jan 2019 10.45 am 24 Feb 2019 3.15 pm 15 Dec 2018 1.30 am 15 Dec 2018 3.15 pm 35 10 yes Mandari n English Table Q1.2 Each scheduled tour is identified by the tour code of the tour it is scheduled for, appended with the schedule code and separated by a hyphen, e.g., JA321-1 for the tour scheduled that departs on 5 Nov 2018 at 3.30 pm. Different languages (English, Mandarin, Malay, Tamil etc.,) may be used to conduct the same tour departing either on the same or different departure dates. When a tour is scheduled to depart during peak period, a surcharge of 25% of the tour cost applies. A booking can be made for a scheduled tour if it is open and if there are available seats. The number of available seats is decreased accordingly. Implement the ScheduledTour and PeakScheduledTour, a subclass of ScheduledTour. A PeakScheduledTour is a ScheduledTour that departs during a peak period and incurs a surcharge of 25% of the tour cost. i)         The superclass ScheduledTour has the following members: - the instance variables for the following pieces of data a tour, a schedule code, language departure date and time capacity available seat and whether the scheduled tour is open for booking. - methods: Getter methods o code which is tour code of the tour it is scheduled for, appended with the schedule code and separated by a hyphen, e.g., JA321-1 o cost which is the cost of the tour, o departure date and time, capacity, seats available and whether the tour is open. SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 3 of 22 ICT162 Tutor-Marked Assignment     Getter and setter methods o the tour it is scheduled for Use the property and setter decorators. A method bookSeats that decrements the seats available when given a positive quantity of seats to book for the scheduled tour. The number of seats available should not become negative. Return true for a successful operation and false otherwise. A method cancelSeats that increments the seats available when given a positive quantity of seats to cancel for the scheduled tour. The number of seats available should not become greater than the capacity. Return true for a successful operation and false otherwise. A method getPenaltyRate that returns the penalty rate for cancelling a seat for the scheduled tour. The rate is dependent on the number of days the cancellation is made before the start of the tour, according to Table Q1.3: Days before start of tour 46 days and beyond Within 45 days Within 20 days Within 7 days Penalty per seat 10% of tour cost 25% of tour cost 50% of tour cost 100% of tour cost Table Q1.3 Any cancellation after the tour has started will incur a penalty rate of 100%.  A class method getHandlingFee that returns the penalty cost of handling a cancellation. The handling fee is $120. o Implement the handling fees as a class variable.  A method changeOpenStatus that makes the scheduled tour open for booking if it is close, and it makes the scheduled tour close for booking if it is open.  A string method that returns all its attributes. Here is an example in the required format: (9 marks) ii) The class PeakScheduledTour is a subclass of ScheduledTour. The class has the same instance variables and methods as ScheduledTour. In addition, the class PeakScheduledTour has the following members:  a class variable for a surcharge of 25% for travel during peak period. The tour cost of PeakScheduledTour is 25% more than that for a scheduled tour that does not depart during period.  a class variable for a handling fees of $200. SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 4 of 22 ICT162 Tutor-Marked Assignment The handling fee for cancellation a seat is $200 instead of $120. There are differences in the implementation of the methods in the subclass PeakScheduledTour as compared to the methods in ScheduledTour.  The cost of the tour should include the surcharge of 25% of the tour cost  The penalty rate for cancellation is an additional penalty rate of 10% more than ScheduledTour, subject to a maximum penalty rate of 100%  __str__ method must indicate the amount of surcharge. Here is an example in the required format: (4 marks) (c) Before making a tour booking, the customer must register. The details for registration include passport number, name, as well as contact and address. Once registered, to make bookings, he needs to supply only his passport number. Test data for five customers is given in Table Q1.4 below: Passport Number E1234567X E7777777X E2323232Y E1111111Y E9999999Y Name Alice Lee Peter Tam Joy Seetoh Mary Tham Sally Koh Contact 98989898 97777777 89898989 85858585 87878787 Address 27F Sea Avenue 8A Gray Lane 15 Sandy Lane 16 Jalan Mydi 1 Joo Heng Road Table Q1.4 Implement the class Customer which has the following members: i)     the instance variables for the following pieces of data: passport number, name contact and address. ii) methods:  Getter methods for all the instance variables,  Setter methods for contact and address  A string method that returns all its attributes. Here is an example in the required format: (3 marks) SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 5 of 22 ICT162 (d) Tutor-Marked Assignment When making a tour booking, the customer must indicate whether the booking is for an individual or for a group. If the customer makes an individual booking, he can decide whether he wishes to stay in a single room. If so, he is required to pay an additional 50% of the cost of the selected scheduled tour. If he makes a group booking, he must enter the size of his group. Each passenger in the group gets a 5% discount if the group size is between 6 and 9, and 10% if the group size is 10 or above. Each booking has a booking id which is generated by the application. The booking id is a running number starting from 1, with an increment of 1. Test data for eight bookings is given in Table Q1.5 below: Type of Booking Individual Individual Group Individual Individual Group Group Group Booked for Scheduled Tour JA312-2 JA312-2 JA312-2 KO111-6 KO111-6 KO111-6 KO111-6 KO111-6 Customer with Passport Number E1234567X E7777777X E2323232Y E1234567X E7777777X E7777777X E2323232Y E1111111Y Single Room? yes no yes no - Size of Group 9 5 6 10 Table Q1.5 Implement the abstract class Booking and its subclasses, IndividualBooking and GroupBooking. i)     The abstract superclass Booking has the following members: - the instance variables for the following pieces of data a booking id, a scheduled tour, a customer and number of seats The constructor of Booking accepts a scheduled tour, a customer and the number of seats for a booking. The number of seats should be used to update the seats available in the scheduled tour. The booking id is auto-generated, using a class variable whose value is incremented with each Booking object. o Implement the class variable that is used in the auto-generation of booking ids. SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 6 of 22 ICT162 Tutor-Marked Assignment      methods: Getter methods o Passport number of the customer who makes the booking o Scheduled tour the booking is made for o Booking id o Number of seats An abstract method that returns the cost of the scheduled tour. A method getPenaltyAmount that returns the penalty cost of cancelling each seat in the booking. The method takes in the number of days which is difference between the date of departure and the date of cancellation or withdrawing from the booking. The penalty amount is a percentage (or the penalty rate) of the scheduled tour cost and a handling fee. The penalty amount should not exceed the amount the customer paid for the scheduled tour. An addSeats method which increases the number of seats in a booking. The addSeats method is successful only if the scheduled tour that the booking is made for has sufficient seats available to accommodate the number of seats to be added. The number of seat available in the scheduled tour must be decreased when the number of the seats in the booking is increased. The method returns true if the operation is successful and false otherwise. A removeSeats method which reduces the number of seats in a group booking. The removeSeats method is successful only if releasing the seats does not cause the seats available in the scheduled tour to exceed the capacity. The number of seat available in the scheduled tour must be increased when the number of the seats in the booking is decreased. addSeats and removeSeats methods, however, may have a different implementation in the subclasses.  A string method that returns all its attributes. Here is an example in the required format: (9 marks) ii)    The subclass IndividualBooking of Booking has the same instance variables and methods of its superclass, Booking. In addition, it has the following members: an instance variable to record whether single room is required or Atherwise. If single room is required, there is a surcharge of 50%. o Implement the surcharge as a class variable A cost method which implements the abstract method in its superclass. The cost method adds the surcharge if the individual booking requires a single room. The addSeats and removeSeats methods return false as there should be SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 7 of 22 ICT162 Tutor-Marked Assignment exactly one seat in an individual booking.  A string method that returns all its attributes. Here are some examples in the required format: (4 marks) iii)    The subclass GroupBooking of Booking has the same instance variables and methods of its superclass, Booking. In addition, it has the following members: a cost method which implements the abstract method in its superclass. The cost method gives a 5% discount if the number of seats booked is between 6 and 9, and a 10% discount if the number of seats booked is at least 10. A removeSeats method which will reduce the number of seats in a group booking only if the number of seats in the booking does not go below 2. A group booking must have at least 2 seats booked. Thus, the removeSeats method is successful only if o the number of seats booked does not go under 2, and o releasing the seats does not cause the seats available in the scheduled tour to exceed the capacity A string method that returns all its attributes. Here are some examples in the required format: (4 marks) SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 8 of 22 ICT162 Tutor-Marked Assignment e) Implement the tour agency class that has the following members:  the instance variables for the following pieces of data:  a collection of tours  a collection of scheduled tours, both peak and normal,  a collection of customers, and  a collection of bookings You may use any appropriate data types to implement the collections.  methods:  4 add methods to o add a tour to the collection of tours o add a scheduled tour to the collection of scheduled tours, both peak and normal schedules o add a customer to the collection of customers o add a booking to the collection of bookings, both individual and group bookings  3 search methods to o search a scheduled tour in the collection of scheduled tours, given its code o search a customer in the collection of customers, given his passport number o search a booking in the collection of bookings, given its booking id These methods return None if the search does not locate the required object.  A method displayBookings to display bookings in the collection.  A method displayOpenScheduledTours to display those scheduled tours in the collection that are open.  A method cancelBooking to remove a booking from the collection, given a booking id. The method returns true if the operation is successful and false otherwise.  A method addSeats to add seats to a booking. This method takes in the booking id and the number of seats to add to a booking. If there are sufficient seats available, the seats are added to the booking and the method returns true. If the operation is unsuccessful, the method returns false.  A method removeSeats to remove seats from a booking. This method takes in the booking id and the number of seats to remove from a booking. The seats must be added back to the scheduled tour the booking is made for. The method returns true if the operation is successful and false otherwise. (8 marks) SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 9 of 22 ICT162 Tutor-Marked Assignment f) Write an application to allow the tour agency staff to manage bookings through this menu: Menu 1. Add Booking 2. Cancel Booking 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit  Initialise the tour agency collection with the test data shown in the various tables.  Run the menu repeatedly until option 0 is selected. Option 1: Add booking After the customer’s passport number is entered, a scheduled tour can be chosen from the list of scheduled tours that are open. A booking can be made either for an individual or for a group. The booking detail is then displayed. If the passport number or the code of the scheduled tour is invalid or if the quantity to book is more than the available seats, an appropriate error message is displayed. Otherwise, the details of the booking is displayed. A sample interaction for option 1 is shown here: Menu 1. Add Booking 2. Cancel Booking 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit Enter option: 1 Enter passport number: E1234567X Code: JA312 Name: Food Trail in Toyko Schedule Code: JA312-2 Language: Mandarin Available: 15 Open: Yes Code: VI102 Name: Vietnam Highlights Schedule Code: VI102-5 Language: English Available: 34 Open: Yes 7D/6N Base Cost: $1999.14 Departure: 15 Jan 2019 10:45 Capacity: 25 5D/4N Base Cost: $999.75 Departure: 24 Feb 2019 15:15 Capacity: 35 Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: Available: 24 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) 50 Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-2 Language: English Departure: 15 Dec 2018 15:15 Capacity: Available: 10 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) 35 Enter schedule code of tour : KO111-6 1. Individual Booking 2. Group Booking Enter choice of booking: 1 1. Single 2. Sharing Enter choice of room: 1 Booking is added Booking Id: 0000000009 Passport Number: E1234567X Name: Alice Lee Contact: 98989898 Address: 27F Sea Avenue Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $2717.55 ($905.85 Single room surcharge) Menu 1. Add Booking 2. Cancel Booking SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 10 of 22 ICT162 Tutor-Marked Assignment 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit Enter option: 1 Enter passport number: E1234567X Code: JA312 Name: Food Trail in Toyko Schedule Code: JA312-2 Language: Mandarin Available: 15 Open: Yes 7D/6N Base Cost: $1999.14 Departure: 15 Jan 2019 10:45 Capacity: 25 Code: VI102 Name: Vietnam Highlights Schedule Code: VI102-5 Language: English Available: 34 Open: Yes 5D/4N Base Cost: $999.75 Departure: 24 Feb 2019 15:15 Capacity: 35 Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) 50 Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-2 Language: English Departure: 15 Dec 2018 15:15 Capacity: Available: 10 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) 35 Enter schedule code of tour : JA312-2 1. Individual Booking 2. Group Booking Enter choice of booking: 2 Enter number of seats to book (max 15): 10 Booking is added Booking Id: 0000000010 Passport Number: E1234567X Name: Alice Lee Contact: 98989898 Address: 27F Sea Avenue Booked Code: JA312 Name: Food Trail in Toyko 7D/6N Base Cost: $1999.14 Schedule Code: JA312-2 Language: Mandarin Departure: 15 Jan 2019 10:45 Capacity: 25 Available: 5 Open: Yes Final Cost per pax: $1799.23 per pax for group size of 10 (with 10% discount) Option 2: Cancel booking To cancel a booking, the booking id of the booking to be cancelled and the date of cancellation are first entered. The days between the cancellation date and the tour departure date is computed to determine the penalty rate. The booking detail and the penalty are then displayed. This option should display an appropriate message to indicate whether the cancellation is successful. A sample interaction for option 2 is shown here: Menu 1. Add Booking 2. Cancel Booking 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit Enter option: 2 Enter booking number: 9 Enter date (d/m/y): 2/1/2019 Booking Id: 0000000009 Passport Number: E1234567X Name: Alice Lee Contact: 98989898 Address: 27F Sea Avenue Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $2717.55 ($905.85 Single room surcharge) Penalty of $1830.53 per seat removed applies Cancel booking is successful Option 3: Add Seats to Booking For this option, the booking id of the booking and the number of seats to be added are first entered. The details of the booking before and after the add seats operation is performed are displayed. The cost of each added seats and a discount for existing seats, if applicable, are also displayed. If there is any error, an appropriate error message is displayed. Otherwise, the details of the booking before and after SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 11 of 22 ICT162 Tutor-Marked Assignment performing the operation are displayed. A sample interaction for option 3 is shown here: Menu 1. Add Booking 2. Cancel Booking 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit Enter option: 3 Enter booking number: 7 Enter number of seats to add: 5 Booking Id: 0000000007 Passport Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1721.11 per pax for group size of 6 (with 5% discount) Booking Id: 0000000007 Passport Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 18 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1630.53 per pax for group size of 11 (with 10% discount) Please pay $1630.53 per seat Discount of $90.58 per existing seat Add seats is successful Option 4: Remove Seats from Booking In this option, the booking id of the booking, the number of seats to be removed and the date of the request to remove seats are first entered. The details of the booking before and after the operation is performed are displayed. The penalty amount, the refund amount and a top up for each remaining seats, if applicable, are also displayed. If there is any error, an appropriate error message is displayed. Otherwise, the details of the booking before and after performing the operation are displayed. A sample interaction for option 4 is shown here: Menu 1. Add Booking 2. Cancel Booking 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit Enter option: 4 Enter booking number: 7 Enter number of seats to remove: 5 Enter date (d/m/y): 10/12/2018 Booking Id: 0000000007 Passport Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 18 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1630.53 per pax for group size of 11 (with 10% discount) Booking Id: 0000000007 Passport Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1721.11 per pax for group size of 6 (with 5% discount) Penalty of $1630.53 per seat removed applies Refund amount $0.00 per seat Require top up of $90.58 per seat Remove seats is successful SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 12 of 22 ICT162 Tutor-Marked Assignment Option 5: Display Booking This option displays all bookings that have been made. A sample interaction for option 5 is shown here: Menu 1. Add Booking 2. Cancel Booking 3. Add Seats to Booking 4. Remove Seats from Booking 5. Display Booking 0. Exit Enter option: 5 Booking Id: 0000000001 Passport Number: E1234567X Name: Alice Lee Contact: 98989898 Address: 27F Sea Avenue Booked Code: JA312 Name: Food Trail in Toyko 7D/6N Base Cost: $1999.14 Schedule Code: JA312-1 Language: English Departure: 5 Nov 2018 15:30 Capacity: 35 Available: 7 Open: No Final Cost per pax: $2998.71 ($999.57 Single room surcharge) Booking Id: 0000000002 Passport Number: E7777777X Name: Peter Tam Contact: 97777777 Address: 8A Gray Lane Booked Code: JA312 Name: Food Trail in Toyko 7D/6N Base Cost: $1999.14 Schedule Code: JA312-1 Language: English Departure: 5 Nov 2018 15:30 Capacity: 35 Available: 7 Open: No Final Cost per pax: $1999.14 (No single room surcharge) Booking Id: 0000000003 Passport Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane Booked Code: JA312 Name: Food Trail in Toyko 7D/6N Base Cost: $1999.14 Schedule Code: JA312-2 Language: Mandarin Departure: 15 Jan 2019 10:45 Capacity: 25 Available: 5 Open: Yes Final Cost per pax: $1899.18 per pax for group size of 9 (with 5% discount) Booking Id: 0000000004 Passport Number: E1234567X Name: Alice Lee Contact: 98989898 Address: 27F Sea Avenue Booked Code: JA312 Name: Food Trail in Toyko 7D/6N Base Cost: $1999.14 Schedule Code: JA312-2 Language: Mandarin Departure: 15 Jan 2019 10:45 Capacity: 25 Available: 5 Open: Yes Final Cost per pax: $2998.71 ($999.57 Single room surcharge) Booking Id: 0000000005 Passport Number: E7777777X Name: Peter Tam Contact: 97777777 Address: 8A Gray Lane Booked Code: VI102 Name: Vietnam Highlights 5D/4N Base Cost: $999.75 Schedule Code: VI102-5 Language: English Departure: 24 Feb 2019 15:15 Capacity: 35 Available: 34 Open: Yes Final Cost per pax: $999.75 (No single room surcharge) Booking Id: 0000000006 Passport Number: E7777777X Name: Peter Tam Contact: 97777777 Address: 8A Gray Lane Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1811.70 per pax for group size of 5 (No group discount applies) Booking Id: 0000000007 Passport Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane Booked Code: KO111 Name: Discover Korea 8D/7N Base Cost: $1449.36 Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: 50 Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1721.11 per pax for group size of 6 (with 5% discount) Booking Id: 0000000008 Passport Number: E1111111Y Name: Mary Tham Jalan Mydi Booked Code: KO111 Name: Discover Korea SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Contact: 85858585 8D/7N Address: 16 Base Cost: $1449.36 Page 13 of 22 ICT162 Tutor-Marked Assignment Schedule Code: KO111-6 Language: Mandarin Departure: 15 Dec 2018 01:30 Capacity: Available: 23 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies) Final Cost per pax: $1630.53 per pax for group size of 10 (with 10% discount) 50 Booking Id: 0000000010 Passport Number: E1234567X Name: Alice Lee Contact: 98989898 Address: 27F Sea Avenue Booked Code: JA312 Name: Food Trail in Toyko 7D/6N Base Cost: $1999.14 Schedule Code: JA312-2 Language: Mandarin Departure: 15 Jan 2019 10:45 Capacity: 25 Available: 5 Open: Yes Final Cost per pax: $1799.23 per pax for group size of 10 (with 10% discount) (13 marks) Question 2 You are given the class Product that has a code and quantity on hand, the relevant getter and setter methods and the string method. class Product: def __init__(self, code, qtyOnHand): self._code = code self._qtyOnHand = qtyOnHand @property def code(self): return self._code @property def qtyOnHand(self): return self._qtyOnHand @qtyOnHand.setter def qtyOnHand(self, qtyOnHand): self._qtyOnHand = qtyOnHand def __str__(self): return 'Code: {:5s} Quantity: {:3d}'.format(self._code, self._qtyOnHand) (a) Implement two user exception classes  ProductException which is a subclass of Exception.  DetailProductException which is a subclass of ProductException o DetailProductException has an instance variable, the failed product(s) o It has a getter method to return the failed product(s) (4 marks) (b) Implement the class ProductList which has the following members:  A dictionary to store a collection of Product objects. Use the product code as the key in the dictionary.  A search method that returns a product given the code. The method returns None if the product is not in the collection.  An add method that adds a product into the collection when given a code and a quantity. Raise a ProductException if the product already exists in the collection with an appropriate message that includes the product code. Otherwise, return the product added. SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 14 of 22 ICT162 Tutor-Marked Assignment  A remove method that removes a product from the collection when given a code. Raise a ProductException if the product does not exist in the collection with an appropriate message that includes the product code. Otherwise, if the quantity on hand of the product is not zero, raise a DetailProductException and the product and a message that there is still some quantity of the product.  A list method that displays all the products in the collection.  An addStock method that takes in as argument a collection of products, each with a code and quantity on hand. For each product in the (argument) collection, o if it exists in the ProductList object, update the quantity on hand of corresponding product with its quantity on hand. o if it does not exist in the ProductList object, add the product to an error list. Raise a DetailProductException with the error list and with an appropriate message if there are products with non-matching code. (8 marks) (c) Write an application that allows a ProductList object to be managed using the options from the menu: Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Option 1: Add To add a product, the product code and the quantity are first entered. If the product to be added already exists in the ProductList object, a ProductException would have been raised. Therefore, this option must handle the exception raised. It does so by printing the exception message. The outcome of the operation must be displayed. If no exception is raised, the product is added to the ProductList object. A sample interaction for option 1 is shown here: Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:1 Enter code of product to add:123 Enter quantity of product:25 Product added Code: 123 Quantity: 25 Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:1 Enter code of product to add:123 Enter quantity of product:12 Product code 123 exists! SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 15 of 22 ICT162 Tutor-Marked Assignment Option 2: Remove There are three scenarios when the remove operation is requested.  A ProductException is raised if the product code is invalid, that is, the remove operation is attempting to remove a non-existent product in the ProductList object. This option will handle the exception raised by printing the exception message.  A DetailProductException is raised if there is still some quantity of the product, that is, the remove operation is attempting to remove a product with stock. This option will handle the exception raised by checking with the user whether the stock of the product is to be written off. If so, the product is removed from the ProductList object. Otherwise, the product is not removed.  The product with zero stock is removed without error. The outcome of the operation must be displayed. A sample interaction for option 2 is shown here for the scenario that there are 3 products in the collection: Code: 1 Code: 2 Code: 3 Quantity: Quantity: Quantity: 20 5 0 Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:2 Enter code of product to remove:5 Product code 5 does not exist! Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:2 Enter code of product to remove:1 There is still some stock of the product! Do you want to write off stock (y/n):n Okay, product is not removed Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:2 Enter code of product to remove:2 There is still some stock of the product! Do you want to write off stock (y/n):y Product is removed Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:2 Enter code of product to remove:3 Remove is successful SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 16 of 22 ICT162 Tutor-Marked Assignment Option 3: Update This option allows the user to build a collection of products and the quantity to be added to the corresponding products in the ProductList object. There are two scenarios when the update operation is requested.  A DetailProductException is raised if there are products to update the ProductList but these products are not in the ProductList object. This option will handle the exception raised by checking with the user whether each of these products should to be added to the collection in the ProductList object instead. If so, the product is added to the ProductList object. Otherwise, the product is not added.  There is no product that does not have a match in the ProductList object. The outcome of the operation must be displayed. A sample interaction for option 3 followed by option 4, is shown here given that there are 3 products in the collection in the ProductList object: Code: 1 Quantity: 20 Code: 2 Quantity: 0 Code: 3 Quantity: 5 Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:3 Enter code of product to add stock to or enter to end:2 Enter quantity of product:10 Enter code of product to add stock to or enter to end:4 Enter quantity of product:13 Enter code of product to add stock to or enter to end:3 Enter quantity of product:10 Enter code of product to add stock to or enter to end:5 Enter quantity of product:14 Enter code of product to add stock to or enter to end: Some updates do not match existing product! Do you want to add this product, Code: 4 Quantity: Product added Code: 4 Quantity: 13 Do you want to add this product, Code: 5 Quantity: Failed products are resolved Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:4 Code: 1 Quantity: Code: 2 Quantity: Code: 3 Quantity: Code: 4 Quantity: 13 (y/n)? y 14 (y/n)? n 20 10 15 13 Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:3 Enter code of product to add stock to or enter to end:1 Enter quantity of product:5 Enter code of product to add stock to or enter to end:2 Enter quantity of product:5 Enter code of product to add stock to or enter to end: Update is complete Menu SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 17 of 22 ICT162 Tutor-Marked Assignment 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:4 Code: 1 Quantity: Code: 2 Quantity: Code: 3 Quantity: Code: 4 Quantity: 25 15 15 13 Option 4: List This option allows the user to display the collection of products in the ProductList object, as demonstrated in the output for a sample run under option 3. A sample interaction for option 4 is shown here when there is no product in the ProductList object: Menu 1.Add 2.Remove 3.Update 4.List 0.Exit Enter option:4 Product list is empty (8 marks) Question 3 Implement a simple graphical user interface (GUI) to simulate a cash register for a burger outlet which serves three types of burger. Burger Code B C F Name Beef Burger Chicken Burger Fish burger Price 12.95 5.95 7.95 Table Q3.1 The cash register maintains two dictionaries:  One dictionary records the burger details: burger code, name and price as shown in Table Q3.1, with burger code as the key to access name and price  One dictionary records the current purchase details: the burger code and the quantity with burger code as the key to access quantity. Table Q3.2 shows an example purchase consisting of 2 beef burgers and 1 chicken burger. Burger Code B C Quantity 2 1 Table Q3.2 SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 18 of 22 ICT162 Tutor-Marked Assignment Figure Q3.1 shows how the GUI looks initially like: the Add to Purchase button is enabled but the rest of the buttons: Delete Purchase Item, Confirm Purchase and Clear buttons are disabled. Figure Q3.1 Figure Q3.2a and Figure Q3.2b show how the GUI looks like before and after the Add to Purchase button has been clicked. Notice that once the purchase is non-empty, the buttons Delete Purchase Item, Confirm Purchase and Clear buttons are enabled, the purchase detail is reflected in the scroll text area and the fields for burger code and quantity are cleared. Figure Q3.2a Figure Q3.2b If the field for quantity is not entered, the quantity is assumed to be 1 as shown in Figure Q3.2c and Figure Q3.2d. The current purchase is displayed whenever it is updated, and the burgers are displayed in alphabetical order. SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 19 of 22 ICT162 Tutor-Marked Assignment Figure Q3.2c Figure Q3.2d If the item code is not entered or is invalid, show an error message on the scrolled text area as shown in the last 2 lines of the scrolled test area in Figure Q3.2e. If the radio button for Staff is selected, the purchase will get a 20% discount as shown in Figure Q3.3f. Figure Q3.2e SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 20 of 22 ICT162 Tutor-Marked Assignment Figure 3.2f Before the purchase is confirmed, the purchase items can be removed, as shown is Figure Q3.3a to Figure Q3.3d. Whenever the purchase is empty, only the Add to Purchase button is enabled. Figure Q3.3a Figure Q3.3b SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 21 of 22 ICT162 Tutor-Marked Assignment Figure Q3.3c Figure Q3.3d When a purchase is confirmed, the scrolled text area displays only the details of the confirmed purchase, and only the Clear button is enabled as shown in Figure Q3.4a and Figure Q3.4b. When Clear button is clicked, the GUI is ready for the next purchase transaction, as shown in Figure Q3.1. Figure Q3.4a Figure Q3.4b (20 marks) ---- END OF ASSIGNMENT ---- SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 22 of 22
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

At...


Anonymous
Great! Studypool always delivers quality work.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags