ICT162 Tutor-Marked Assignment
This assignment is worth 24% of the final mark for ICT162, Object Oriented Programming .
The cut-off date for this assignment is Wednesday, 26 April 2023, 2355 hrs .
Note to Students: Submit your solution document in the form of a single MS Word file. You are to include the following particulars in your submission: Course Code, Title of the TMA, SUSS PI No., Your Name, and Submission Date. Put this information in the first page of your solution document. Use the template word document provided – SUSS_PI_No-FullName_162TMA.docx. Rename the file with your SUSS_PI_No, FullName, and read the submission details under Module\TMA01 in the ICT162 L01 . Do NOT submit as a pdf document . You should make only one submission for TMA. You are to copy and paste Python source code into your solution document as text. If you submit source code as image, no marks will be awarded to your program. Submit screenshots for only output of your program, where applicable.
Assignment Requirements: Unless specified in the question, you CANNOT use packages not covered in this module, e.g., re, collections, numpy, pandas etc. All classes must be documented. Provide sufficient comments to your code and ensure that your program adheres to good programming practices such as not using global variables. Failing to do so can incur a penalty of as much as 50% of the mark allotted.
To start, SAMI will rollout 2 types of room – Standard (2m x 2.1m) and Deluxe (2.3m x 2.1m). During the booking, guests will first select a room type, then they will decide on their preferred bed type – Single (1.9m x 0.91m) or Super (1.9m x 1.07m). By default, the bed includes a pillow and a blanket. SAMI will also offer the following type of amenities, as “option” for guests to add-on. General: Wi-Fi, Gym Pass, Pool Pass, Pillow, Blanket Toiletries: Shampoo, Shower Gel, Bath Towel, Bathrobe, Hand Towel Personal care: Shaving Cream, Razor, Shower Cap, Hair Dryer, Slippers Furniture: Walled-TV, Fridge, Bedside Table, Coffee Kit, Writing Desk, Chair Price per day will be the sum of room price, bed price and the selected amenities’ prices.
ICT162 Tutor-Marked Assignment Question 1 (5 marks) Let’s start with the Guest. Construct the Guest class according to the specification in the class diagram shown below in Figure Q1.
adopted the blacklisting strategy where misbehaving guests are prevented from (future) booking with SAMI. If guest is blacklisted, the list will contain pairings of date and reason for each offence. Constructor performs the following: o Initialises these 3 instance variables: _passport, _name and _country, with the given Question 2 (15 marks) 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. Study the class diagram in Figure Q2, which focuses on the Amenity class and its subclasses.
Figure Q2 (a) Implement the abstract class – Amenity.
The Amenity class has: THREE instance variables: o _itemCode (str): unique code for this amenity item, e.g., “GYM_PEP”. o _description (str): description of the amenity, e.g., “Per entry pass to gym (Level
The SharedAmenity class is also a subclass of Amenity. No additional instance variable. For shared amenities, the method getFloorArea returns 0, as these amenities are mostly in shared/common area, or not occupying any floor area of the room. E.g., gym, swimming pool, Wi-Fi etc. (5 marks)
(c) Write a main() function to do the following: (i) Assemble 4 Amenity objects into a list. o From Appendix A.1, select and create 2 SharedAmenity objects. o From Appendix A.2, select and create 2 InRoomAmenity objects with floor area
0.1 m2 (ii) Print the total floor area and total price of the Amenity objects created in Q2(c)(i).
(5 marks) ICT162 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 7 of 29 Question 3 (20 marks) As illustrated in the introduction, SAMI follows the minimalist design style – simple, clean, and functional, by providing each room with an open floor plan, allowing guest to select their preferred bed type, and option to add amenities. In Figure Q3, the class diagram is updated with Room and Bed classes, to mimic the hotel room setup.
Figure Q3 (a) Implement the Bed class. The Bed class has: It has a class variable: _TYPE_SIZE that is a Dictionary containing the 2 bed types and their floor area, as key and value respectively. THREE instance variables: o _type (str): only “Single” or “Super” bed types currently offered by SAMI.
ICT162 Tutor-Marked Assignment floorArea is obtained through the class variable _TYPE_SIZE, using the instance variable _type. The str method returns a string representation of a Bed object, in the following order – description and price, separated by commas: Super single bed with one pillow and one blanket, $12.99 (4 marks) (b) Create the following exception classes. BookingException – subclass of the Exception class. This class has no added attribute or method. When the application encounters booking rules violation, your application will raise an exception from this class. MinFloorAreaException – subclass of the Exception class. This class has no added attribute or method. o In Singapore, there is a requirement to maintain a minimum floor area and passageway to facilitate safe and swift exit in event of emergency. o When adding amenities to room, the minimum floor area rule may be violated. Your application will raise an exception from this class. (1 mark) (c) Construct and Implement the Room class. The Room class has: TWO class variables: o _MIN_EXIT_SPACE: minimum floor area (1.84m2) that should be kept clear. o _TYPE_SIZE that is a Dictionary containing the 2 room types and their floor area, as key and value respectively. FOUR instance variables: o _type (str): the room type, either “Standard” or “Deluxe”. o _roomPrice (float): representing the price for the room, excluding the bed. o _bed (Bed): the Bed object, which is the preferred bed of the guest. o _amenities (list): a collection (list) containing the “add-on” amenities. Constructor initialises these 3 instance variables: _type, _roomPrice and _bed using the given parameters. The constructor should set _amenities to an empty list. Getter method for instance variables: _type and _roomPrice. Use the property decorator. Define getter method for fullPrice – the sum of room price, bed price and all amenities’ prices. Use the property decorator The addAmenity method has newItem (Amenity object) as parameter. The following checks need to be performed before adding this newItem into _amenities: o The minimum floor area of 1.84m2 must not be compromised after adding this newItem. If the above condition is not met, raise MinFloorAreaException with appropriate message. o In SAMI, there should not be duplicate amenity in each room, i.e., not more than one, raise BookingException with appropriate message if duplicate
Amenity object with the same item code and remove it from the collection _amenities. o If there is no amenity matching the given itemCode, then method should raise BookingException with message stating there is no such amenity in this room. The str method returns the details of the room, follow by the string representations of bed, amenities, and the full price. Below are two examples: Standard room, $16.99 Super single bed with one pillow and one blanket, $12.99 Full Price: $29.98
o Chair o Writing desk o Iron and ironing Board
Standard room with single bed, and add the following amenities in this order: o Gym pass o Mini fridge o Wi-Fi o Gym pass
Print the string representation of the created Room objects.
(ii) Remove these amenities from both rooms, in this order:: o Mini fridge o Gym pass
Print the string representation of the Room objects, after removal. (5 marks) ICT162 Tutor-Marked Assignment Question 4 (40 marks) This question is a continuation of Question 1, 2 & 3, hence will make use of the classes in Question 1, 2 & 3. To stay in SAMI Hotel, you will need to make a booking. As SAMI only offer rooms for individuals, a booking is made up of ONE guest and ONE room. However, a booking can only be submitted and confirmed if there is room available from the check-in to check-out dates. As SAMI Hotel only offer 2 room types, the room availability is provided through a file and released monthly (see Appendix C). If selected room is available on those dates, a booking ID will be generated once the booking is submitted. On the check-in date, the guest will quote the booking ID when arriving at SAMI Hotel. Room allocation and the rest of hotel operations will be manual. In this question, you will create a prototype application for the booking of rooms in SAMI Hotel. SAMI management will observe the demand and decide later if the application is to enhance to support the rest of Hotel operations. Refer to the Booking class diagram in Figure Q4a and the Hotel class diagram in Figure Q4b.
Figure Q4a
(a) Implement the Booking class.
ICT162 Tutor-Marked Assignment It has a class variable: _NEXT_ID, starting from 1, used for generating running numbers to uniquely identify the booking. There are SEVEN instance variables: o _bookingID (str): the booking ID to uniquely identify this booking o _guest (Guest): the Guest object, represent the guest who make this booking. o _room (Room): the Room object, representing the room, including the bed and amenities selected by the guest. o _checkInDate (date): check-in date. o _checkOutDate (date) : check-out date. o _allocatedRoomNo (str): this field is empty when booking is made, and will be updated by SAMI when the guest check-in. o _status (str): status of the booking. Constructor performs the following: o Initialises these 4 instance variables: _guest, _room, _checkInDate and _checkOutDate, using the given parameters. o The _bookingID is generated using the class variable _NEXT_ID, which starts from 1, and increment by 1 for every new booking. o Set _allocatedRoomNo to None, and _status to “Pending”. o Ensure the guest is not backlisted, or check-out date is at least 1 day after check- in date. Otherwise, raise BookingException with appropriate message. Define the following getter methods, using the property decorator: o Instance variables: _bookingID, _checkInDate, _checkOutDate and _status. o For the following: passport – returns the passport of the guest. roomType – returns the room’s type. totalPrice – returns the product of fullPrice of room and number of nights. Setter methods for instance variable: _status. Use the property decorator. Method checkIn will first check if the following rules are not violated: o Current booking status must be “Confirmed”. o The check-in must be done on the _checkInDate itself. o Check that the guest is not blacklisted. o If any of the above condition is not met, raise BookingException with appropriate message. The method then proceed to perform the following: o Update _status to “Checked-In”. o Update _allocatedRoomNo with the given parameter. Figure Q4b You are to complete a partially written Hotel class, given in Appendix E. The Python codes for Hotel class only have constructor and setup methods for guests, amenities, and room availability.
Description of the instance variables and constructor of the Hotel class: It has FIVE instance variables: o _name (str): the name of the hotel. o _guests (dictionary): collection of guests. The key for this dictionary is the passport number, and the value is the Guest object. o _amenities (list): the list of amenities that SAMI is providing. o _bookings (dictionary): collection of bookings. The key for this dictionary is the booking ID, and the value is the Booking object. o _roomAvailability (dictionary): the room availability as shown in Appendix C. The key for this dictionary is the date, and the value is a list holding the standard room count and deluxe room count. Given name and roomFilename as parameters, the constructor performs the following: o Initialises the instance variable: _name, using the given parameter “name”. o Invoke the setupGuest method – to setup Guest objects into the dictionary by reading the information from “Guests.txt” and “Blacklist.txt”.
ICT162 Tutor-Marked Assignment Invoke the setupAmenities method – to setup the current set of Amenity objects into a list using the information provided in Appendix A.1 & A.2. o Invoke the saveRoomAvailability method, with the roomFilename, to setup the room availability as shown in Appendix C. o Setup _bookings as empty dictionary.
You are to write the following methods of the Hotel class: Given a passport (number) as parameter, the method searchGuest searches and returns the Guest object matching this passport number. If not found, the method returns None. checkRoomAvailability method will return True if there is room (type) available from parameter start (date) to parameter end (date). The method returns False, if: o start date is later than end date. o start or end dates are not in the _roomAvailability dictionary. listAmenity method returns the string representation of all Amenity objects, concatenated and one Amenity object per line. Given an itemCode as parameter, the getAmenity method searches and returns the Amenity object that matches the parameter itemCode. If there is no such amenity, the method returns None. searchBooking method has 1 parameter: bookingID (int). This method searches and returns the Booking object that matches the parameter bookingID. If there is no such booking, the method returns None. Given passport (str) as parameter, the searchBookingByPassport method searches and returns a list containing all the Booking objects with guest’s passport matching the parameter passport. An empty list is returned if there is no booking found. The submitBooking method also has a newBooking (Booking object) as parameter. This method is invoked when the booking is ready for submission. The following validation tasks need to be performed: o Check that the newBooking status is “Pending”. o Check that there should be room available for this booking (from check-in to check-out date, for the room type). o If any of the above checks fail, this method should raise BookingException with appropriate messages. If there is no exception, then proceed to: o Update room availability by deducting the room type count from check-in to check-out dates. o Update the booking status to “Confirmed”. o Add this newBooking object into _bookings dictionary. cancelBooking method has bookingID as parameter and need to perform the following checks: o If there is no booking with this booking ID, then method should raise BookingException with message saying there is no such booking. o If this booking ID can locate a booking, but the booking status is not “Confirmed”, then method should raise BookingException with message stating this booking cannot be cancelled. ICT162 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 14 of 29 o Update the booking status to “Cancelled” and update the room availability data (increment room type count by 1 from check-in to check-out dates) The checkIn method has 2 parameters: bookingID and allocatedRoomNo. This method will perform the following: o Search for this booking using the given bookingID. o If booking is found, invoke the checkIn method of the Booking object. o If no such booking, then method should raise BookingException with proper message. (18 marks)
(c) Write an application that allow SAMI to manage the room booking processes, focusing on the creation, submission, and cancellation of bookings. As this is an experimental project, the actual room allocation and check-in procedure will be done manually. Hence, your application will provide a shortened “Check-In” function to just update the status and room allocated for the bookings.
====================
- Submit Booking
- Cancel Booking
- Search Booking(s)
- Check-In
- Exit Enter option: 1 Enter Passport Number to start: a9001022 Guest located. Please verify
Passport: A9001022 Name: Steve Tan Country: Malaysia
Select preferred room type (S)tandard or (D)eluxe): S Select preferred bed type (S)ingle or s(U)per: S
WI-FI, One-day Wi-Fi access, $1.00 GYM-PEP, Per entry pass to gym (Level 4-01), $1.00 SWIM-PEP, Per entry pass to swimming pool (Level 2 outdoor), $1.50 BIZ-PEP, Per entry pass to business centre (Level 3-03), $2.00 BREAKFAST, Breakfast buffet at Sun café (Level 1-01, 6am to 10am), $8.99 Hi-TEA, Hi-Tea buffet at Sun café (Level 1-01 2pm to 4pm), $11.99 SHAMPOO-1, One sachet of conditioning shampoo, $0.29 SHOWER-1, One sachet of shower gel, $0.25 TOWEL-B, One bath towel (to return when check-out), $1.50 TOWEL-H, One hand towel (to return when check-out), $1.00 SHOW-CAP, One shower cap, $0.49 SHA-RAZOR, One disposable shaving razor (men’s), $2.99 SHA-CREAM, One sachet of shaving cream (men’s), $0.29 HAIR-DRY, Hair Dryer (to return when check-out), $2.00 SLIPPERS, One pair of disposable slippers , $4.59 WALLED-TV, Walled-TV, $3.99 FRIDGE, Mini Fridge (50L), $4.59 TABLE-B, Bedside table (60cm x 50cm), $2.59 DESK-W, Writing desk (80cm x 55cm), $3.99 CHAIR, Foldable Chair (42cm x 38cm), $2.59 IRON-B, Iron and ironing board (128cm x 30cm), $2.99
Enter item code to add or
List of Amenities
WI-FI, One-day Wi-Fi access, $1.00 GYM-PEP, Per entry pass to gym (Level 4-01), $1.00 SWIM-PEP, Per entry pass to swimming pool (Level 2 outdoor), $1.50 BIZ-PEP, Per entry pass to business centre (Level 3-03), $2.00 BREAKFAST, Breakfast buffet at Sun café (Level 1-01 6am to 10am), $8.99 ICT162 Tutor-Marked Assignment SINGAPORE UNIVERSITY OF SOCIAL SCIENCES (SUSS) Page 16 of 29 . . . WALLED-TV, Walled-TV, $3.99 FRIDGE, Mini Fridge (50L), $4.59 TABLE-B, Bedside table (60cm x 50cm), $2.59 DESK-W, Writing desk (80cm x 55cm), $3.99 CHAIR, Foldable Chair (42cm x 38cm), $2.59 IRON-B, Iron and ironing board (128cm x 30cm), $2.99
o Label “Date Reported:” & “(dd-mon-yyyy)” to guide user input (Entry) for the date of incident. o Label “Reason(s):” to guide user input (Entry) to record reason(s) for blacklisting this guest. o 3 Buttons “Search” (enabled), “Blacklist” (disabled) and “Reset” (disabled). o Scrolled Text (disabled) to display search results, blacklisting outcome, or any messages. In this prototype GUI, re-instating blacklisted guests or removal of incidents are not in scope. (7 marks)
ICT162 Tutor-Marked Assignment
(b) Implement event handling so that the SAMI Blacklisting GUI can respond to left button clicks on these buttons.
Format of the file:
Each line of the file contains information in this order: