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 Number of Days Number of Nights Cost($)
JA312 Food Trail in Tokyo 7 6 1999.14
K0111 Discover Korea 8 7 1449.36
VI102 Vietname Highlights 5 4 999.75

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: K0111 Name: Discover Korea 8D/7N Base Cost: $1449.36

(b) 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 Schedule Scheduled for Tour with tour code Schedule Code Language Departure Date and time Capacity Available Seats Is Open
Normal JA312 1 English 5 Nov 2018 3.30 pm 35 9 no
JA312 2 Mandarin 15 Jan 2019 10.45 am 25 25 yes
VI102 5 English 24 Feb 2019 3.15 pm 35 35 Yes
Peak KO111 6 Mandarin 15 Dec 2018 1.30 am 50 45 yes
KO111 2 English 15 Dec 2018 3.15 pm 35 10 yes

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 Scheduled Tour and Peak ScheduledTour, a subclass of ScheduledTour. A Peak Scheduled Tour is a Scheduled Tour 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
    • 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
    • cost which is the cost of the tour, o departure date and time, capacity, seats available and whether the tour is open
  • Getter and setter methods
    • 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 retums 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 01.3:

Days before start of tour Penalty per seat
46 days and beyond 10% of tour cost
Within 35 days 25% of tour cost
Within 20 days 50% of tour cost
Within 7 days 100% of tour cost

Any cancellation after the tour has started will incur a penalty rate of 100%.

  • A class method getHandling Fee that returns the penalty cost of handling a cancellation. The handling fee is $120.
    • Implement the handling fees as a class variable.
  • A method change OpenStatus 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:

JA312 Name: Food Trail in Tokyo 7D/6N Base Cost: $1999.14
Code: 1A312-1 Language: English Departure: 5 Nov 2018 15:30 Capacity: 35 Available: 9 Open: No

ii) The class PeakScheduledTour is a subclass of Scheduled Tour. The class has the same instance variables and methods as ScheduledTour.

In addition, the class Peak Scheduled Tour has the following members:

  • a class variable for a surcharge of 25% for travel during peak period. The tour cost of Peak Scheduled Tour is 25% more than that for a scheduled tour that does not depart during period.
  • a class variable for a handling fees of $200.

The handling fee for cancellation a seat is $200 instead of $120.

There are differences in the implementation of the methods in the subclass Peak Scheduled Tour 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 Scheduled Tour, subject to a maximum penalty rate of 100%
  • __str__ method must indicate the amount of surcharge. Here is an example in the required format:
Code: K0011 : Discover Korea 3D/7N Base Cost: $1449.36
Schedule Code: 0111-6 Language: Mandarin Departure: 15 Dec 2818 81:38 Capacity: 30 Available: 25 Open: Yes Cost: $1811.70 ($362.34 peak surcharge applies)

(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 Name Contact Address
E1234567X Alice Lee 98989898 27F Sea Avenue
E7777777X Peter Tam 97777777 8A Gray Lane
E2323232Y Joy Seetoh 89898989 15 Sandy Lane
E1111111Y Mary Tham 85858585 16 Jalan Mydi
E9999999Y Sally Koh 87878787 1 Joo Heng Road

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) method:

  • 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:

port Number: E2323232Y Name: Joy Seetoh Contact: 89898989 Address: 15 Sandy Lane

(d) 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 Booked for Customer with Passport Scheduled Customer with Passport Number Single Room? Size of Group
Individual JA312-2 E1234567X yes -
Individual JA312-2 E7777777X no -
Group JA312-2 E2323232Y - 9
Individual KO111-6 E1234567X yes
Individual KO111-6 E7777777X no -
Group KO111-6 E7777777X - 5
Group KO111-6 E2323232Y - 6
Group KO111-6 E1111111Y - 10

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 member 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.

- methods

  • Getter methods
    • Passport number of the customer who makes the booking
    • Scheduled tour the booking is made for
    • Booking id
    • 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 n 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:
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:38 Capacity: 35 Available: 7 Open: No

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%
    • 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 exactly one seat in an individual booking.
  • A string method that returns all its attributes.

Here are some examples in the required format:

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 Tan 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:39 Capacity: 35 Available: 7 Open: No
Final Cost per pax: $1999.14 (No single room surcharge)

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
    • the number of seats booked does not go under 2, and
    • 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: see image.

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
    • add a tour to the collection of tours
    • add a scheduled tour to the collection of scheduled tours, both peak and normal schedules
    • add a customer to the collection of customers
    • add a booking to the collection of bookings, both individual and group bookings
  • 3 search methods to
    • search a scheduled tour in the collection of scheduled tours, given its code
    • search a customer in the collection of customers, given his passport number
    • 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 displayOpenScheduled Tours 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.

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: see image.

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: see image.

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 performing the operation are displayed.

A sample interaction for option 3 is shown here: see image.

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: see image.

Option 5: Display Booking

This option displays all bookings that have been made. A sample interaction for option S is shown here: see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.