Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The picture is just a hint, the code is at the bottom. Starter Code: : import random class Course: ''' >>> c1 = Course('CMPSC132',

The picture is just a hint, the code is at the bottom.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Starter Code:

: """

import random

class Course: ''' >>> c1 = Course('CMPSC132', 'Programming in Python II', 3) >>> c2 = Course('CMPSC360', 'Discrete Mathematics', 3) >>> c1 == c2 False >>> c3 = Course('CMPSC132', 'Programming in Python II', 3) >>> c1 == c3 True >>> c1 CMPSC132(3): Programming in Python II >>> c2 CMPSC360(3): Discrete Mathematics >>> c3 CMPSC132(3): Programming in Python II >>> c1 == None False >>> print(c1) CMPSC132(3): Programming in Python II ''' def __init__(self, cid, cname, credits): # YOUR CODE STARTS HERE pass

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

def __eq__(self, other): # YOUR CODE STARTS HERE pass

class Catalog: ''' >>> C = Catalog() >>> C.addCourse('CMPSC132', 'Programming in Python II', 3) 'Course added successfully' >>> C.addCourse('CMPSC360', 'Discrete Mathematics', 3) 'Course added successfully' >>> C.courseOfferings {'CMPSC132': CMPSC132(3): Programming in Python II, 'CMPSC360': CMPSC360(3): Discrete Mathematics} >>> C.removeCourse('CMPSC360') 'Course removed successfully' >>> C.courseOfferings {'CMPSC132': CMPSC132(3): Programming in Python II} ''' def __init__(self): # YOUR CODE STARTS HERE pass

def addCourse(self, cid, cname, credits): # YOUR CODE STARTS HERE pass

def removeCourse(self, cid): # YOUR CODE STARTS HERE pass

class Semester: '''

def __init__(self, sem_num): # --- YOUR CODE STARTS HERE pass

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

def addCourse(self, course): # YOUR CODE STARTS HERE pass

def dropCourse(self, course): # YOUR CODE STARTS HERE pass

@property def totalCredits(self): # YOUR CODE STARTS HERE pass

@property def isFullTime(self): # YOUR CODE STARTS HERE pass

class Loan: ''' '''

def __init__(self, amount): # YOUR CODE STARTS HERE pass

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

@property def __loanID(self): # YOUR CODE STARTS HERE pass

def __init__(self, name, ssn): # YOUR CODE STARTS HERE pass

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

def get_ssn(self): # YOUR CODE STARTS HERE pass

def __eq__(self, other): # YOUR CODE STARTS HERE pass

class Staff(Person): ''' def __init__(self, name, ssn, supervisor=None): # YOUR CODE STARTS HERE pass

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

@property def id(self): # YOUR CODE STARTS HERE pass

@property def getSupervisor(self): # YOUR CODE STARTS HERE pass

def setSupervisor(self, new_supervisor): # YOUR CODE STARTS HERE pass

def applyHold(self, student): # YOUR CODE STARTS HERE pass

def removeHold(self, student): # YOUR CODE STARTS HERE pass

def unenrollStudent(self, student): # YOUR CODE STARTS HERE pass

class Student(Person): ''' >>> C = Catalog() >>> C.addCourse('CMPSC132', 'Programming in Python II', 3) 'Course added successfully' >>> C.addCourse('CMPSC360', 'Discrete Mathematics', 3) 'Course added successfully' >>> s1 = Student('Jason Lee', '204-99-2890', 'Freshman') >>> s1 Student(Jason Lee, jl2890, Freshman) >>> s2 = Student('Karen Lee', '247-01-2670', 'Sophomore') >>> s2 Student(Karen Lee, kl2670, Sophomore) >>> s1 == s2 False ''' def __init__(self, name, ssn, year): random.seed(1) # YOUR CODE STARTS HERE

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

def __createStudentAccount(self): # YOUR CODE STARTS HERE pass

@property def id(self): # YOUR CODE STARTS HERE pass

def registerSemester(self): # YOUR CODE STARTS HERE pass

def enrollCourse(self, cid, catalog, semester): # YOUR CODE STARTS HERE pass

def dropCourse(self, cid, semester): # YOUR CODE STARTS HERE pass

def getLoan(self, amount): # YOUR CODE STARTS HERE pass

class StudentAccount: def __init__(self, student): # YOUR CODE STARTS HERE pass

def __str__(self): # YOUR CODE STARTS HERE pass

__repr__ = __str__

def makePayment(self, amount, loan_id=None): # YOUR CODE STARTS HERE pass

def chargeAccount(self, amount): # YOUR CODE STARTS HERE pass

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 (depends on Course) o Stores a collection of Course objects through a dictionary, using id as the key. Semester (depends on Course) 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. Student Account (depends on Student) 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) (depends on Person, Student) o Represents a person who is a staff member and has a supervisor. Student (subclass of Person) (depends on most of the above classes) 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 str cid Description Stands for course id, uniquely identifies a course like "CMPSC132". Stands for course name and is the long form of the course title. The number of credits a course is worth, str chame credits int Special methods Type Name str _str_(self) str _repr__(self) eq__(self, other) Description Returns a formatted summary of the course as a string. Returns the same formatted summary as_str_ Does an equality check based only on course id. bool str_(self), _repr_(self) Returns a formatted summary of the course as a string. The format to use is: cid(credits): chame Output Formatted summary of the course. str __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 as a dictionary, accessible by their ids. Attributes Type Name dict courseOfferings Description Stores courses with the id as the key and the course as the value. Methods Type Name addCourse(self, cid, cname, credits) str removeCourse(self, cid) str Description Adds a course with the given information, Removes a course with the given id. addCourse(self, cid, ename, credits) Creates a Course object with the parameters and stores it as a value in courscOfferings. Inputs (excluding self) str cid The id of the course to add. str cianie The name of the course to add int credits The number of credits the course is worth. Output str "Course added successfully" "Course already added" if course is already in courseOfferings. str removeCourse(self, cid) Removes a course with the given id. Input (excluding self) str cid The id of the course to remove. Output "Course removed successfully" "Course not found" if a course with the given id is not in the dictionary. str str Section 4: The Semester class Stores a collection of Course objects for a semester for a student. Attributes Type Name int sem num list courses Description The semester number for this object. The list of courses to be taken this semester. Methods Type Name (many) addCourse(self, course) (many) dropCourse(self course) int totalCredits(self) bool isFull Time(self) Description Adds a course to courses if it is a valid course object. Removes a course from courses. A property method for the total number of credits. A property method that returns True if this is full-time. Special methods Type Name Description _str_(self) Returns a formatted summary of the all the courses in this semester. str repr_(self) Returns the same formatted summary as str. str addCourse(self, course) Adds a course to courses if it is a valid course object. Input (excluding self) Course Course The Course object to add to this semester. Output None str (Normal operation does not output anything) "Invalid course the course object has invalid attributes. "Course already added" if the course is already in this semester. str drop Course(self, course) Removes a course from this semester Input (excluding self) Course course The Course object to remove from this semester. Output None str Nonnal operation does not output anything "Invalid course" the course object has invalid attributes "No such course" if the course is not in this semester. str Section 4: The Semester class totalCredits(self) A properly method (behaves like an attribute) for the total number of credits in this semester. Outputs (normal) int Total number of cnrolled credits in this semester. is Full Time(self) A property method (behaves like an attribute) that checks if a student taking this semester would be considered full-time (takiny 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) Retuis a formatted summary of the all the courses in this semester. Use the format: cid, cid, cid, ... Output Formatted summary of the courses in this semester. str "No courses" if the semester has no courses. str Section 5: The Loan class A class that represents an amount of money, identified by a pseudo-random number. Attributes Type Name int loan id int amount Description The id for this loan, generated pseudo-randomly. The amount of money loaned. Methods Type Name int loanID(self) Description A property method that pseudo-randomly generates loan ids. Special methods Type Name str str (self) str _repr_(self) Description Returns a formatted summary of the loan as a string. 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. loanID(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. 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 Student student numerical balance dict loans Description The Student object that owns this StudentAccount. The balance that the student has to pay. A dictionary that stores Loan objects accessible by their loan id. Methods Type Name numerical makePayment(sell, amount) numerical chargeAccount(self, amount) Description Makes a payment towards the balance. Adds an amount towards the balance. Special methods Type Name str _str_(self) str repr (self) Description Returns a fonnalted summary of the loan as a string. Returns the same formatted sunimary as str makePayment(self, amount) Makes a payment by subtracting the payment amount from the balance. Input (excluding self) numerical amount The payment amount towards the balance. Output numerical Current balance amount. chargeAccount(self, amount) Adds an amount towards the balance. Inputs (excluding selt) int amount The amount to add to the balance. Output int Updated balance amount _str_(self), _repr_(self) Returns a formatted summary of the loan as a string. The format to use is (spread out over three lines): Name: name Output ID: id str Formatted summary of the account. Balance: balance Section 7: The Person class This class is a basic representation of a person, storing name and social security number. Attributes Type Name str name Description Full name of the person. Private attribute of social security number formatted as 123-45-6789". str san Methods Type Name Description str get_ssn(self) Getter method for accessing social security number. Special methods Type Name str str (self) str _repr__(self) bool eq__(sell, other) Description Returns a formatted summary of the person as a string. Returns the same formatted summary as str Checks for equality by comparing only the ssn attributes. get_ssn(self) Getter method for accessing the private social security number attribute. Output str Social security number. _str_(self), _repr__(self) Returns a formatted summary of the person as a string. The format to use is: Person(name, ***-**-last four digits) Output str Formatted summary of the person. ____(self, other) Determines if two objects are cqual. For instances of this class, we will define equality when the SSN of one object is the same as SSN of the other object. You can assume at least one of the objects is a Person object. Input (excluding self) many other The other object to check for equality with. Output bool True if other is a Person object with the same SSN, False otherwise. Section 8: The Staff class This class inherits from the Person class but adds extended functionality for staff members. Attributes, methods, and special methods inherited from Person are not listed in this section. Attributes Type Name Staff supervisor Description A private attribute for this person's supervisor. By default, set to None. Methods Type Name Description str id(self) Property method for generating staff's id. (many) setSupervisor(self, new_supervisor) Updates the private supervisor attribute. (many) getSupervisor(self) Property method for getting the supervisor. (many) applyHold(self, student) Applies a hold on a student object. (many) removeHold(self, student) Removes a hold on a student object. (many) unenrollStudent(self, student) Sets a student's status to not active. Special methods Type Name str _str_(self) str _repr__(self) Description Returns a formatted summary of the staff as a string. Returns the same formatted summary as str. id(self) Property method (behaves like an attribute) for generating staff's id. The format should be: 905 initials+last four numbers of ssn. (e.g.: 905abc6789), Ignore the security flaws this generation method presents and assume ids are unique. Output Generated id for the staff member, str setSupervisor(self, new_supervisor) Updates the private supervisor attribute Input (excluding self) Staff new_supervisor The new value to set for the supervisor attribute. Output str "Completed!" None Nothing is returned if new_supervisor is not a Staff object. getSupervisor(self) Property method (bchaves like an attribute) for getting the supervisor. Output Staff Current value of supervisor. Section 8: The Staff class applyHold(self, student) Applies a hold on a student object (set the student's hold attribute to True). Input (excluding self) Student student The student to apply a hold to. Output str "Completed!" None Nothing is returned if student is not a Student object. removeHold(self, student) Removes a hold on a student object (set the student's hold attribute to False). Inputs (excluding self) Student student The student to remove a hold from. Output str None "Completed!" Nothing is returned if student is not a Student object. unenrollStudent(self, student) Unenrolls a student object (set the student's active attribute to False). Inputs (excluding selt) Student student The student to uncnroll. Output str None "Completed!" Nothing is returned if student is not a Student object. _str_(self), __repr_(self) Returns a formatted summary of the staff member as a string. The format to use is: Staff name, id) Outputs (normal) str Formatted summary of the staff member. Section 9: The Student class This class inherits from the Person class and is heavy extended for additional functionality. Attributes, methods, and special methods inherited from Person are not listed in this section. Name Attributes Type str dict bool bool Student Account year semesters hold active account Description A string indicating the student's year ("Freshman", etc.). A collection of Semester objects accessible by sem_num. Indicates a hold on the student's account, defaults to False. Indicates if the student is actively enrolled, defaults to True. The current balance of the student, Methods Type str Student Account (many) str Name Description id(self) Property method for generating student's id, _create StudentAccount (self) Creates a Student Account object. register Semester sell) Creates a Semester object. enrollCourse(self, cid, catalog. Enrolls the student in a course. semester) dropCoursc(self, cid, Drops a course from a semester. semester) getLoan(self, amount) Creates a Loan object. str (many) Special methods Type Name str str_(self) str repr_(self) Description Returns a formatted summary of the staff as a string. Returns the same formatted summary as str id(self) Property method (bchaves like an attribute) for generating student's id. The format should be: initialst last four numbers of ssn (e.g.: abc6789). Ignore the security flaws this generation method presents and assumc ids are unique. Output str Student's id. createStudent Account(self) Creates a StudentAccount object. This should be saved in the account attribute during initialization. Output StudentAccount Created StudentAccount object linked to the student. None Nothing is returned if student is not active. Section 9: The Student class registerSemester(self) Creates a Semester object and adds it as a value to the semesters dictionary if the student is active and has no holds. It also updates the student's year attribute according to the number of semesters enrolled. 'Freshman is a first-year student (semesters 1 and 2), 'Sophomore' is a second-year student (semesters 3 and 4), "Junior' is a third-year student (semesters 5 and 6) and Senior' for any enrollment with more than 6 semesters. Output None (Normal operation does not output anything) str "Unsuccessful operation" is returned if the student is inactive or has holds. cnrollCourse(self, cid, catalog, semester) Finds a Course object with the given id from the catalog and adds it to the courses attribute of the Semester object. Charge the student's account the appropriate amount of money. Inputs (excluding self) str cid Course ID to search for. Catalog catalog Catalog to scarch in. int semester The semester number to add the course to. Output "Course added successfully" "Unsuccessful operation" is returned if the student is inactive or has holds, "Course not found" is returned if no course with the given id is found. "Course already enrolled" is returned if the course is already enrolled. str drop Course(self, cid, semester) Finds a Course object from the specified semester with the given id and removes it. When a course is dropped, no money is refunded to the student's account, Inputs (excluding sell) cid Course ID to search for. int semester The semester number to search in. Output str "Course dropped successfully" "Unsuccessful operation" is returned if the student is inactive or has holds. "Course not found" is returned if no course with the given id is found. Section 9: The Student class getLoan(self, amount) If the student is active and currently enrolled full-time (consider the item with the largest key in the semesters dictionary the current enrollment), il creates a Loan object for the student with the given amount, adds it to the student's account's loans dictionary, and uses the amount to make a payment in the student's account. Do NOT remove the line random.seed (1) from the constructor. This ensures replicablc pseudo-random number generation across multiple cxccutions, so your loan ids should match the doctest samples. Inputs (excluding sell) int amount The amount of money to get a loan for. Output None (Normal operation does not return anything) str "Unsuccessful operation" is returned if the student is inactive. "Not full-time" is returned if the current semester is not full-time str Section 10: The create Student function The createStudent function is a separate function that should be outside of any classes. createStudent(person) Creates a Student object from a Person objcct. The new student should have the same information (name, ssn) as the person and starts out as a freshman ("Freshman"). Input Person person The Person object to create a Student object from. Output Student The new student created from the input Person object

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions

Question

explain what is meant by redundancy

Answered: 1 week ago