Professional Documents
Culture Documents
Practice Paper
Practice Paper
1. The following classes model the the courses, instructors and course schedule offered by a
training provider.
The Course class models a course with code, title and development cost. The Instructor class models
an instructor with email, name, and how much the instructor charges per day.
The CourseSchedule class models a schedule of the course by an instructor, with a start date and
duration in days.
Assume that the python code for Course class is already provided.
a) Write the Instructor class according to the class diagram given, with the 3 attributes, a
constructor, getter method for email, and getter and setter method for ratePerDay attribute.
The __str__() method returns a string in the following format:
Instructor email: xxx@yyy.com Name: Joe Wong
(the second line of the string comes from the __str__() method of the Course Class)
2. The following classes model customers who make reservations from the training provider.
The Reservation is an abstract class, with the following attributes and methods:
- It has a class variable _id =1 which is used as a counter for the reservationId attribute.
- It has other attributes, custEmail custName, courseSchedule and reservationDate.
- Besides the constructor, it has an abstract method courseFee() with no implementation.
- The __str__() method returns information on the reservation in the following format:
Reservation Id: 1 Email : a@b.com Name: John Reservation Date: 10/4/2020
Schedule Id: PY214_1 Start Date: 1/6/2020 Duration: 3 days
Course Code: PY214 Course Name: Introduction to Python
Instructor email: xxx@yyy.com Name: Joe Wong
Course fee: $999.99
The TrainingProvider class has a collection of course schedules. It has the provider name as attribute
and a dictionary collection to store CourseSchedule objects. The course schedule id is the key and
the value is the object.
The code for the GUI is provided, but the event handlers for the Add/Search/List buttons are not.
You are NOT required to rewrite the whole program again, but indicate only the statement number
which needs modification and also the statement number where code should be inserted.
A dictionary to store instructors is provided in line 6. For Add button, create an Instructor object
based on the 3 text fields and add the object to the dictionary. The key is the email, and the value
the Instructor object. There is no need to consider blank fields, but a message “Instructor already
added!” should be displayed if another instructor of the same email is added. Display “Instructor
added!” if the instructor is added successfully to the dictionary.
For Search button, retrieve the Instructor object based on the email entered in the email text field.
Display the details in the scrolled text using the __str__ of the instructor object. If no instructor is
found, display “No instructor with this emai!”.
The List button simply displays all the instructors in the scrolled text, one instructor per line. If the
dictionary is empty, display “No instructors”.
1. from tkinter import *
2. from tkinter.scrolledtext import ScrolledText
3.
4. class TrainingProviderGUI():
5. def __init__(self):
6. self._instructors = {}
7. self._tk = Tk()
8. self._tk.geometry('270x200')
9. self._tk.title("Training Provider")
10. self.createWidgets()
11. self._tk.mainloop()
12.
13. def createWidgets(self):
14. inputFrame = Frame(self._tk)
15. lblEmail = Label(inputFrame, text='Email: ')
16. self._tbxEmail = Entry(inputFrame, width=15)
17. lblEmail.grid(row=0, column=0, sticky=W)
18. self._tbxEmail.grid(row=0, column=1, sticky=W)
19.
20. lblName = Label(inputFrame, text='Name: ')
21. self._tbxName=Entry(inputFrame, width=25)
22. lblName.grid(row=1, column=0, sticky=W)
23. self._tbxName.grid(row=1, column=1, sticky=W)
24.
25. lblRate = Label(inputFrame, text='Rate per day: ')
26. self._tbxRate=Entry(inputFrame, width=10)
27. lblRate.grid(row=2, column=0, sticky=W)
28. self._tbxRate.grid(row=2, column=1, sticky=W)
29.
30. inputFrame.grid(row=0, column=0)
31. buttonFrame = Frame(self._tk)
32. self._btnSearch = Button(buttonFrame, text='Add')
33. self._btnModify = Button(buttonFrame, text='Search')
34. self._btnList = Button(buttonFrame, text='List')
35. self._btnSearch.grid(row=0, column=1)
36. self._btnModify.grid(row=0, column=2, padx=5)
37. self._btnList.grid(row=0, column=3)
38.
39. scrollFrame = Frame(self._tk)
40. self._sclText = ScrolledText(scrollFrame, width=30, height=5,
wrap=WORD)
41. self._sclText.grid(row=0, column=0)
42. inputFrame.grid(row=0, column=0, pady=5)
43. scrollFrame.grid(row=2, column=0, pady=5)
44. buttonFrame.grid(row=1, column=0 )
~ end ~