Reference no: EM132355798
Question
Having the hardest time with this, any help/explanation greatly appreciated!
Design a Python project manage_course. Add a Python file course.py to this project.
Define a class Course in this file. This class has three publicly accessible instance variables to store course code, quota and enrollment.
Define the following methods:
(a) An __init__ method that accepts the course code and quota as arguments. Write statements in __init__ to store them in instance variables. Also form an instance variable to store enrollment and initialize it to 0.
(b) An add_student method to increase enrollment by one and display "One student added" if the course is not full. If the course is already full, make no change to enrollment and display "Course already full". This method has no argument other than self and has no return value.
(c) A drop_student method to decrease enrollment by one and display "One student dropped" if the course is not empty. If the course is empty, make no change to enrollment and display "Course is empty". This method has no argument other than self and has no return value.
The following class diagram shows the design of this class:
Course
+course code: String
+quota: Integer
+enrollment: Integer
+create(code:String, quota:Integer)
+add_student()
+drop_student()
Add a file manage_course_main.py to this project. This is the main module. Build code to ask the user to enter course code and quota of a course.
Use the data provided by the user to put together an instance of Course.
Design a loop to manage this course. In the loop, ask the user to enter 1 for adding a student, 2 for dropping a student, 3 for displaying course info, or 0 for exit.
If 1 is chosen, call the add_student method of the Course object and use a print statement to display updated enrollment.
If 2 is chosen, call the drop_student method of the Course object and use a print statement to display updated enrollment. If 3 is chosen, display values stored in the Course object to show course code, quota and enrollment.
The following shows a sample test run:
Enter course code: CSC121
Enter course quota: 3
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 2
Course is empty.
Enrollment: 0
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 1
One student added.
Enrollment: 1
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 1
One student added.
Enrollment: 2
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 1
One student added.
Enrollment: 3
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 1
Course already full.
Enrollment: 3
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 2
One student dropped
Enrollment: 2
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 3
Course code: CSC121
Quota: 3
Enrollment: 2
Enter 1 for add student, 2 for drop student, 3 for course info, 0 for exit: 0