Question: this is the code , i need this code modified please as explained in the screenshots. class Department(): univ_students = 0 count = 0 def
this is the code , i need this code modified please as explained in the screenshots.
class Department():
univ_students = 0 count = 0 def __init__(self, d_code= '', d_name = '', capacity = 5, minGPA = 2.5): self.d_code = d_code self.d_name = d_name self.capacity = capacity self.minGPA = minGPA self.num_students = 0 self.avgGPA = 0.0 self.roster = [ ]
self.reason = '' Department.count += 1 def __str__(self): return('Department ' + self.d_code + ' ' + self.d_name + ' ' + ' capacity= ' + str(self.capacity) + ' number of students= ' + str(self.num_students) + ' min GPA= ' + str(self.minGPA)) def addStudent(self, s_obj): if not s_obj or not isinstance(s_obj, Student): return False, 'add failed: obj type' else: self.qualified, self.reason = self.isQualified(s_obj) if self.qualified: self.roster.append(s_obj) self.num_students += 1 Department.univ_students += 1 self.calcAvgGPA() s_obj.setMajor(self.d_code) # set Student's major to Dept else: return False, self.reason return True, 'added' def isQualified (self, s_obj): if self.num_students >= self.capacity: # Check Dept. capacity return (False, 'add failed: over capacity') elif s_obj.gpa() min return (False, 'add failed: minGPA') elif not s_obj.isEnrolled(): # Student must be enrolled return (False, 'add failed: not enrolled') else: if len(self.roster) > 0: # Check student not already for s in self.roster: # in Dept. major roster if s.sameStudent(s_obj): return (False, 'add failed: already in Department') return (True, '') def calcAvgGPA(self): # recalculates Dept. avg GPA self.avgGPA = 0 for s in self.roster: self.avgGPA += s.gpa() return (round(self.avgGPA / len(self.roster),2)) def printRoster(self): print(' List of students in Department ', self.d_name) for s in self.roster: print(s)
class Student():
def __init__(self, g_num, name, status = 'Freshman', major = 'IST', enrolled = 'y', credits = 0, qpoints = 0): self.g_num = str(g_num) self.name = str(name) self.status = str(status) self.major = str(major) self.enrolled = str(enrolled) self.credits = credits self.qpoints = qpoints def __str__(self): return(str(self.name) + ', ' + str(self.g_num) + ', ' + str(self.status) + ', ' + str(self.major) + ', active: ' + str(self.enrolled) + ', credits = ' + str(self.credits) + ', gpa = {0:4.2f}'.format(self.gpa())) # calculate gpa, don't store def gpa (self) : if self.credits > 0: # prevent division by zero... return self.qpoints / self.credits else : return 0 # ...if zero credits, return gpa = 0 def setMajor (self, major) : self.major = major return True def sameStudent (self, s_obj): return(self.g_num == str(s_obj.g_num) and self.name == str(s_obj.name) ) # return True if g_num, name match def isEnrolled (self): return (self.enrolled == 'y') # return True if student is enrolled
print(' Start of Department and Student class demo **************') s1 = Student('G34523', 'Arian Khrosadni', status = 'sophomore', major = 'ACC', enrolled = 'y', credits = 30, qpoints = 90) s2 = Student('G21354', 'Saba Arjmand', status = 'senior', major = 'BIO', enrolled = 'y', credits = 90, qpoints = 315) s3 = Student('G42176', 'Parham Tabibi', status = 'sophomore', major = 'CSC', enrolled = 'y', credits = 45, qpoints = 160) s4 = Student('G10944', 'Ariain Ziaee', status = 'junior', major = 'IT', enrolled = 'y', credits = 70, qpoints = 225) s5 = Student('G22164', 'Mojgan Salehi', status = 'senior', major = 'ART', enrolled = 'y', credits = 105, qpoints = 290) s6 = Student('G31378', 'Anahita Khorsandi', status = 'freshman', major = 'HIS', enrolled = 'y', credits = 15, qpoints = 35) s7 = Student('G44523', 'Amirali Shirazi', status = 'junior', major = 'ENG', enrolled = 'y', credits = 65, qpoints = 250) s8 = Student('G55388', 'Shahrokh Gholi', status = 'sophomore', major = 'IT', enrolled = 'y', credits = 45, qpoints = 120) s9 = Student('G66104', 'Ali Amiri', status = 'freshman', major = 'ART', enrolled = 'y', credits = 15, qpoints = 45) s10 = Student('G11332', 'Parisa Shafiei', status = 'senior', major = 'BUS', enrolled = 'y', credits = 110, qpoints = 275) s11 = Student('G22143', 'Kimia Jafari', status = 'junior', major = 'ENG', enrolled = 'y', credits = 85, qpoints = 250) s12 = Student('G31310', 'Golsana Ziaee', status = 'sophomore', major = 'CSC', enrolled = 'y', credits = 45, qpoints = 120) s13 = Student('G31309', 'Melika Izadi', status = 'sophomore', major = 'BIO', enrolled = 'n', credits = 45, qpoints = 120) s14 = Student('G11183', 'Amir Khorsandi', status = 'freshman', major = 'ACC', enrolled = 'y', credits = 20, qpoints = 38) print('List of Students created: ') print('s2= ',s1) print('s2= ',s2) print('s3= ',s3) print('s4= ',s4) print('s5= ',s5) print('s6= ',s6) print('s7= ',s7) print('s8= ',s8) print('s9= ', s9) print('s10= ',s10) print('s11= ',s11) print('s12= ',s12) print('s13= ',s13) print('s14= ',s14) d1 = Department('ENGR', 'Engineering', 5, 2.75) d2 = Department('ARTS', 'Art and Architecture', 15, 2.0) d3 = Department('CHHS', 'College of Health and Human Sevrices', 10, 2.5) print(' Departments established:') print(d1) print(d2) print(d3) print(' Adding s1 - s5 to ENGR Department- print Roster follows') d1.addStudent(s1) d1.addStudent(s2) d1.addStudent(s3) d1.addStudent(s4) d1.addStudent(s5) d1.printRoster() a, b = d1.addStudent(s6) print(' Attempting to add ', s6.name, ' to ', d1.d_code, ' - over capacity, retvalues: ', a, b) d1.printRoster() print(' Adding ', s6.name, ' and ', s7.name, ' to ', d2.d_code, ', printRosterfollows: ') d2.addStudent(s6) d2.addStudent(s7) d2.printRoster() print(' Adding ', s8.name, ' and ', s9.name, ' to ', d3.d_code, ', printRosterfollows: ') d3.addStudent(s8) a, b = d3.addStudent(s9) print(' Attempting to add qualified student , ', s9.name, ' to ', d3.d_code, ',CHHS, return values; ', a, b) d3.printRoster() a, b = d3.addStudent(s14) print(' Attempting to add low GPA student ', s14.name, ', return values: ', a, b) a, b = d2.addStudent(s13) print(' Attempting to add non-enrolled student ', s13.name, ', return values: ', a, b) a, b = d3.addStudent(s8) print(' Attempting to add dupe student ', s8.name, ', return values: ', a, b) print(' Adding s10 to ENGR, s11 to ARTS, s12 to CHHS, then print all 3 roster') d1.addStudent(s10) d2.addStudent(s11) d3.addStudent(s12) d1.printRoster() d2.printRoster() d3.printRoster()



In this assignment you will modify the Department and Student Classes in A3 to use inheritance. Specifically, a generic 'Person' class will be created to hold basic things about a person. The Student class, and a new class named 'Faculty', will be created as subclasses to Person. Person will have the following attributes and methods: aaAttribute Definition g' number identifier individual's name ndividual s address individual's telephone number individual's email address str num name address telephone email str Method Name Purpose Input See above None Output/returns None Constructor - sets initial attribute values in above table Displays a readable version of Person Person: ' + g num +name + address Compares "self" Person's g num and name Person with the input Person object - returns True if object match, otherwise returns False nit str Person data as a rintable strin True if g num and name match, otherwise False samePerson In this assignment you will modify the Department and Student Classes in A3 to use inheritance. Specifically, a generic 'Person' class will be created to hold basic things about a person. The Student class, and a new class named 'Faculty', will be created as subclasses to Person. Person will have the following attributes and methods: aaAttribute Definition g' number identifier individual's name ndividual s address individual's telephone number individual's email address str num name address telephone email str Method Name Purpose Input See above None Output/returns None Constructor - sets initial attribute values in above table Displays a readable version of Person Person: ' + g num +name + address Compares "self" Person's g num and name Person with the input Person object - returns True if object match, otherwise returns False nit str Person data as a rintable strin True if g num and name match, otherwise False samePerson
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
