In python, please complete both sections   Section 3: 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. 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 4: 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) intPseudo-randomly generated id.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
In python, please complete both sections
 
Section 3: 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.

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 4: 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)
intPseudo-randomly generated id.
Expert Solution
Step 1

Python Code

import random
class Course:
def __init__(self, cid, cname, credits):
self.cid = cid
self.cname = cname
self.credits = credits

def __str__(self):
return f"{self.cid}({self.credits}) : {self.cname}"
def __repr__(self):
return f"{self.cid}({self.credits}) : {self.cname}"
def __eq__(self, other):
if(other is None):
return False
if(self.cid==other.cid):
return True
else:
return False
def isValid(self):
if(type(self.cid)==str and type(self.cname)==str and type(self.credits)==int):
return True
return False

class Catalog:
def __init__(self):
self.courseOfferings = {}
def addCourse(self, cid, cname, credits):
self.courseOfferings[cid] = Course(cid,cname,credits)
return "Course Added successfully"
def removeCourse(self, cid):
del self.courseOfferings[cid]
return "Course removed successfully"
class Semester:
def __init__(self, sem_num):
self.sem_num = sem_num
self.courses = []
def __str__(self):
if(len(self.courses)==0):
return "No courses"
else:
formattedS = ""
for course in self.courses:
formattedS += str(course)
formattedS += ","
return formattedS
def __repr__(self):
if(len(self.courses)==0):
return "No courses"
else:
formattedS = ""
for course in self.courses:
formattedS += str(course)
formattedS += ","
return formattedS
def addCourse(self, course):
if(not isinstance(course,Course) or not course.isValid()):
return "Invalid Course"
if(course in self.courses):
return "Course already added"
else:
self.courses.append(course)
def dropCourse(self, course):
if(not isinstance(course,Course) or not course.isValid()):
return "Invalid Course"
if(course not in self.courses):
return "No such course"
else:
self.courses.remove(course)
@property
def totalCredits(self):
totalcredit = 0
for course in self.courses:
totalcredit += course.credits
return totalcredit
  
@property
def isFullTime(self):
if(self.totalCredits>=12):
return True
return False

class Loan:
def __init__(self, amount):
self.loan_id = self.__loanID
self.amount = amount
def __str__(self):
return f"Balance: {self.amount}"
def __repr__(self):
return f"Balance: {self.amount}"
@property
def __loanID(self):
return random.randint(10000,99999)

class Person:
def __init__(self, name, ssn):
self.name = name
self.__ssn = ssn
def __str__(self):
return f"Person({self.name},***-**-{self.get_ssn()[-4:]}"
def __repr__(self):
return f"Person({self.name},***-**-{self.get_ssn()[-4:]}"
def get_ssn(self):
return self.__ssn
def __eq__(self, other):
if(self.get_ssn()==other.get_ssn()):
return True
return False
class Staff(Person):
def __init__(self, name, ssn, supervisor=None):
Person.__init__(self,name,ssn)
self.supervisor = supervisor
def __str__(self):
return f"Staff({self.name},{self.id})"
def __repr__(self):
return f"Staff({self.name},{self.id})"
@property
def id(self):
return "905" + self.name.split()[0][0].lower() + self.name.split()[1][0].lower() + self.get_ssn()[-4:]
@property   
def getSupervisor(self):
return self.supervisor
def setSupervisor(self, new_supervisor):
if(type(new_supervisor)!="Staff"):
return None
else:
self.supervisor = new_supervisor
return "Completed"
def applyHold(self, student):
if(not isinstance(student,Student)):
return None
else:
student.hold = True
return "Completed"
def removeHold(self, student):
if(not isinstance(student,Student)):
return None
else:
student.hold = False
return "Completed"
def unenrollStudent(self, student):
if(not isinstance(student,Student)):
return None
else:
student.active = False
return "Completed"

class Student(Person):
def __init__(self, name, ssn, year):
random.seed(1)
Person.__init__(self,name,ssn)
self.year = year
self.semesters = {}
self.hold = False
self.active = True
self.account = self.__createStudentAccount()
def __createStudentAccount(self):
if(not self.active):
return None
return StudentAccount(self)

@property
def id(self):
return self.name.split()[0][0].lower() + self.name.split()[1][0].lower() + self.get_ssn()[-4:]
def registerSemester(self):
if(not self.active or self.hold):
return "Unsuccessful Operation"
else:
self.semesters[str(len(self.semesters)+1)] = Semester(len(self.semesters)+1)

def enrollCourse(self, cid, catalog, semester):
if(not self.active or self.hold):
return "Unsuccessful Operation"
for ccid in catalog.courseOfferings:
if(ccid==cid):
if(catalog.courseOfferings[cid] in self.semesters[str(semester)].courses):
return "Course already enrolled"
self.semesters[str(semester)].courses.append(catalog.courseOfferings[cid])
self.account.balance += ((self.account.ppc)*(catalog.courseOfferings[cid]).credits)
return "Course added successfully"
return "Course not found"
def dropCourse(self, cid, semester):
if(not self.active or self.hold):
return "Unsuccessful Operation"
for course in semester.courses:
if(cid==course.cid):
semester.courses.remove(course)
self.account.balance -= ((self.account.ppc)*course.credits)
return "Course Dropped Successfully"
return "Course not found"
def getLoan(self, amount):
l = Loan(amount)
if(not self.active):
return "Unsuccessful Operation"
if(len(self.semesters)==0):
return "Student is not enrolled in any of semesters yet"
if(len(self.semesters)>0):
if(not self.semesters[str(len(self.semesters))].isFullTime):
return "Not Full-time"
if(l.loan_id in StudentAccount(self).loans):
self.account.loans[l.loan_id] += amount
else:
self.account.loans[l.loan_id] = amount

class StudentAccount:
  
def __init__(self, student):
self.student = student
self.ppc = 1000
self.balance = 0
self.loans = {}
def __str__(self):
return f"Name: {self.student.name} \n ID: {self.student.id} \n Balance: ${self.balance}"
def __repr__(self):
return f"Name: {self.student.name} \n ID: {self.student.id} \n Balance: ${self.balance}"
def makePayment(self, amount, loan_id=None):
if(loan_id is None):
self.balance -= amount
return self.balance
else:
if(loan_id not in self.loans):
return None
elif(self.loans[loan_id]<amount):
return f"Loan Balance : {self.loans[loan_id]}"   
else:
self.balance -= amount
self.loans[loan_id] -= amount
return self.balance

def chargeAccount(self, amount):
self.balance += amount
return self.balance
def createStudent(person):
return Student(person.name,person.get_ssn(),"Freshman")

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY