PLEASE COMMENT CODE AND FOLLOW DIRECTIONS OF THE SCREEN SHOT. ESPECIALLY THE THIRD BULLET POINT, ONLY CODE AND EXPLANATION IS NEEDEDThere is no starter code file for this assignment. This means you are free to define any number of classes, method and functions. However you must use the tools discussed in the lectures, Python + SQLite
CMPSC-132: Programming and Computation II Homework 2 (100 points) Due date: September 24th, 2021, 11:59 PM EST Goal: The goal of this assignment is to reinforce the fundamental concepts of object-oriented programming in Python. Through this homework, you should gain a better idea of how to implement a system of classes that build on each other. General instructions: • The work in this assignment must be your own original work and be completed alone. • The instructor and course assistants are available on Teams and with office hours to answer any questions you may have. You may also share testing code on Teams. • A doctest is provided to ensure basic functionality and may not be representative of the full range of test cases we will be checking. Further testing is your responsibility. • Debugging code is also your responsibility. • You may submit more than once before the deadline; only the latest submission will be graded. Assignment-specific instructions: • Download the starter code file from Canvas. Do not change the function names or given starter code in your script. At the end of the starter code, there are instructions on how to run the doctest per class • Each class has different requirements, read them carefully and ask questions if you need clarification. No credit is given for code that does not follow directions. • All methods that output a string must return the string, not print it. Code will not receive credit if you use print to display the output • If you are unable to complete a method, use the pass statement to avoid syntax errors Submission format: • Submit your HW2.py file to the Homework 2 Gradescope assignment before the due date. • As a reminder, code submitted with syntax errors does not receive credit, please run your file before submitting. Section 1: Assignment overview The main concept is to implement classes that represent an in-memory “school database”. There are eight classes you must implement: Course, Catalog, Semester, Loan, Person, Staff, Student and StudentAccount. Each class has its own purpose which will be explained below. You will also implement a standalone function that will help transform a Person into a Student. • Course (no dependencies) o Represents a course, with attributes for id, name, and number of credits. • Catalog (Course class must be implemented) o Stores a collection of Course objects through a dictionary, using id as the key. • Semester (Course class must be implemented) o Stores a collection of Course objects taken together during a semester. • Loan (no dependencies) o Represents an amount of money, with attributes for id and the loan amount. • StudentAccount (Student class must be implemented) o Represents the financial status of a student. • Person (no dependencies) o Represents a person, with attributes for a name and social security number. • Staff (subclass of Person) (Person class must be implemented) o Represents a person who is a staff member and has a supervisor. • Student (subclass of Person) (All classes must be implemented) o Represents a person who is a student that takes courses at the university. A non-comprehensive list of concepts you should know to complete this assignment is: • Basic class syntax / definition in Python (attributes, methods, definitions) • Special/Magic methods • Dictionaries • Encapsulation • Polymorphism through Operator and Method Overloading • Inheritance • Property methods • Firm understanding of what it means for Python to be an “Object-Oriented” language Section 2: The Course class A simple class that stores the id, name, and number of credits for a class. Attributes Type Name Description str cid Stands for course id, uniquely identifies a course like “CMPSC132”. str cname Stands for course name and is the long form of the course title. int credits The number of credits a course is worth. Special methods Type Name Description str __str__(self) Returns a formatted summary of the course as a string. str __repr__(self) Returns the same formatted summary as __str__. bool __eq__(self, other) Does an equality check based only on course id. __str__(self), __repr__(self) Returns a formatted summary of the course as a string. The format to use is: cid(credits): cname Output str Formatted summary of the course. __eq__(self, other) Determines if two objects are equal. For instances of this class, we will define equality when the course id of one object is the same as the course id of the other object. You can assume at least one of the objects is a Couse object. Input (excluding self) any other The object to check for equality against a Course object. Output bool True if other is a Course object with the same course id, False otherwise. Section 3: The Catalog class Stores a collection of Course objects and their capacity as a dictionary, accessible by their ids. Attributes Type Name Description dict courseOfferings Stores courses with the id as the key and a tuple (Course, capacity) as the value. Methods Type Name Description str addCourse(self, cid, cname, credits, capacity) Adds a course with the given information. str removeCourse(self, cid) Removes a course with the given id. addCourse(self, cid, cname, credits, capacity) Creates a Course object with the parameters and stores it as a value in courseOfferings. Inputs (excluding self) str cid The id of the course to add. str cname The name of the course to add int credits The number of credits the course is worth. int capacity The maximum number of students allowed to register in the course Output str “Course added successfully” str “Course already added” if course is already in courseOfferings. removeCourse(self, cid) Removes a course with the given id. Input (excluding self) str cid The id of the course to remove. Output str “Course removed successfully” str “Course not found” if a course with the given id is not in the dictionary. Section 4: The Semester class Stores a collection of Course objects for a semester for a student. Attributes Type Name Description int sem_num The semester number for this object. dict courses Stores courses to be taken in the semester. The id of the course as the key and the Course object as the value. Methods Type Name Description (many) addCourse(self, course) Adds a Course to the courses dictionary (many) dropCourse(self, course) Removes a course from courses. int totalCredits(self) A property method for the total number of credits. bool isFullTime(self) A property method that returns True if this is full-time. Special methods Type Name Description str __str__(self) Returns a formatted summary of the all the courses in this semester. str __repr__(self) Returns the same formatted summary as __str__. addCourse(self, course) Adds a Course to the courses dictionary Input (excluding self) Course course The Course object to add to this semester. Output None (Normal operation does not output anything) str “Course already added” if the course is already in this semester. dropCourse(self, course) Removes a course from this semester. Input (excluding self) Course course The Course object to remove from this semester. Output None Normal operation does not output anything str “No such course” if the course is not in this semester. Section 4: The Semester class totalCredits(self) A property method (behaves like an attribute) for the total number of credits in this semester. Outputs (normal) int Total number of enrolled credits in this semester. isFullTime(self) A property method (behaves like an attribute) that checks if a student taking this semester would be considered full-time (taking 12 or more credits) or not. Outputs (normal) bool True if there are 12 or more credits in this semester, False otherwise. __str__(self), __repr__(self) Returns a formatted summary of the all the courses in this semester. Use the format: cid, cid, cid, … Output str Formatted summary of the courses in this semester. str “No courses” if the semester has no courses. Section 5: The Loan class A class that represents an amount of money, identified by a pseudo-random number. Attributes Type Name Description int loan_id The id for this loan, generated pseudo-randomly by __getloanID int amount The amount of money loaned. Methods Type Name Description int __getloanID(self) A property method that pseudo-randomly generates loan ids. Special methods Type Name Description str __str__(self) Returns a formatted summary of the loan as a string. str __repr__(self) Returns the same formatted summary as __str__. __str__(self), __repr__(self) Returns a formatted summary of the loan as a string. Use the format: Balance: $amount Output str Formatted summary of the loan. __getloanID(self) A property method (behaves like an attribute) that pseudo-randomly generates loan ids. Use the random module to return a number between 10,000 and 99,999. The returned value should be saved to loan_id when initializing Loan objects. randint and randrange could be helpful here! Outputs (normal) int Pseudo-randomly generated id. https://docs.python.org/3/library/random.html https://docs.python.org/3/library/random.html#functions-for-integers https://docs.python.org/3/library/random.html#functions-for-integers Section 6: The StudentAccount class This class represents a financial status of the student based on enrollment and is saved to a Student object as an attribute. This class should also contain an attribute that stores the price per credit, initially $1000/credit. This cost can change at any time and should affect the future price of enrollment for ALL students. Attributes Type Name Description Student student The Student object that owns this StudentAccount. numerical balance The balance that the student has to pay. dict loans A dictionary that stores Loan objects accessible by their loan_id. Methods Type Name Description numerical makePayment(self, amount) Makes a payment towards the balance. numerical chargeAccount(self, amount) Adds an amount towards the balance. Special methods Type Name Description str __str__(self) Returns a formatted summary of the loan as a string. str __repr__(self) Returns the same formatted summary as __str__. makePayment(self, amount) Makes a payment by subtracting amount from the balance. Input (excluding self) numerical amount The payment amount towards the balance. Output numerical Current balance amount. chargeAccount(self, amount) Adds amount towards the balance. Inputs (excluding self) numerical amount The amount to add to the balance. Output numerical Updated balance amount