In python, complete both sections please   Section 5: 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. __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 ID: id Balance: balance Output strFormatted summary of the account.       Section 6: The Person class This class is a basic representation of a person, storing name and social security number. Attributes Type Name Description str name Full name of the person. str ssn Private attribute of social security number formatted as “123-45-6789”. Methods Type Name Description str get_ssn(self) Getter method for accessing social security number. Special methods Type Name Description str __str__(self) Returns a formatted summary of the person as a string. str __repr__(self) Returns the same formatted summary as __str__. bool __eq__(self, other) 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. __eq__(self, other) Determines if two objects are equal. 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 boolTrue if other is a Person object with the same SSN, False otherwise.

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, complete both sections please
 
Section 5: 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.

__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
ID: id
Balance: balance

Output
strFormatted summary of the account.
 
 
 
Section 6: The Person class
This class is a basic representation of a person, storing name and social security number.

Attributes
Type Name Description
str name Full name of the person.
str ssn Private attribute of social security number formatted as “123-45-6789”.

Methods
Type Name Description
str get_ssn(self) Getter method for accessing social security number.

Special methods
Type Name Description
str __str__(self) Returns a formatted summary of the person as a string.
str __repr__(self) Returns the same formatted summary as __str__.
bool __eq__(self, other) 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.

__eq__(self, other)
Determines if two objects are equal. 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
boolTrue if other is a Person object with the same SSN, False otherwise.
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