For Python 3.7+. Step 1: Copy and paste the following code. This will be your basis to do the assignment: class Student: # class variable
For Python 3.7+.
Step 1: Copy and paste the following code. This will be your basis to do the assignment:
class Student:
# class variable to track the number of student object created totalEnrollment=0
# constructor to initialize the object def __init__(self,name,major='IST',enrolled='y',credits=0,qpoints=0):
# incrementing the class variable Student.totalEnrollment+=1 self.name=name self.major=major self.enrolled=enrolled self.credits=credits self.qpoints=qpoints self.g_num="G0000"+str(Student.totalEnrollment)
# method to calculature GPA def gpa(self):
try: return self.qpoints/self.credits except ZeroDivisionError : return 0
# method to provide the string representation of the object def __str__(self):
return self.name+", "+self.g_num+", "+self.status()+", "+\ self.major+", active: "+self.enrolled+" , credits = "+\ str(self.credits)+", "+'%.2f' % self.gpa()
# method to check whether the student is enrolled or not def isEnrolled(self):
if self.enrolled == 'y': return True elif self.enrolled == 'n': return False else: pass
# method to get the student status based on the credits def status(self):
if self.credits 30 and self.credits =60 and self.credits =90: return "Senior" else: pass
# method to check the whether current student object is # same as the other student object by comparing the g_num def sameStudent(self,other):
if self.g_num == other.g_num: return True else: return False
# testing print(' Start of A2 Student class demo ') s1 = Student('David Miller', major = 'Hist',enrolled = 'y', credits = 0, qpoints = 0) s2 = Student('Sonia Fillmore', major = 'Math',enrolled = 'y', credits = 90, qpoints = 315) s3 = Student('A. Einstein', major = 'Phys',enrolled = 'y', credits = 0, qpoints = 0) s4 = Student('W. A. Mozart', major = 'Mus',enrolled = 'n', credits = 29, qpoints = 105) s5 = Student('Sonia Fillmore', major = 'CSci',enrolled = 'y', credits = 60, qpoints = 130) s5.g_num = s2.g_num s6 = Student('Pierre Renoir', major = 'Art',enrolled = 'y', credits = 120, qpoints = 315) print('s1 = ', s1) print('s2 = ', s2) print('s3 = ', s3) print('s4 = ', s4) print('s5 = ', s5) print('s6 = ', s6) print(' Total number of students: ', Student.totalEnrollment) print('The gpa of ', s1.name, ' is ', s2.gpa()) print('Class standing of ', s4.name, ' is ', s4.status()) print('Class standing of ', s2.name, ' is ', s2.status())
if s1.sameStudent(s2): print (s1.name, ' and ', s2.name, ' are the same student') else: print (s1.name, ' and ', s2.name, ' are not the same student') if s2.sameStudent(s5): print (s2.name, ' and ', s5.name, ' are the same student') else: print (s2.name, ' and ', s5.name, ' are not the same student') if s1.isEnrolled(): print (s1.name, ' is currently enrolled') else: print (s1.name, ' is not currently enrolled') if s4.isEnrolled(): print (s4.name, ' is currently enrolled') else: print (s4.name, ' is not currently enrolled')
print(' End of A2 Student class demo')
Step 2: Use the code above to do the following:
HELP NEEDED ASAP PLEASE!!!
#testing print(' Start of Department and Student class demo **************')
s1 = Student('G34568', 'David Miller', status = 'sophomore', major = 'Hist', enrolled = 'y', credits = 30, qpoints = 90) s2 = Student('G21345', 'Sonia Fillmore', status = 'senior', major = 'Math', enrolled = 'y', credits = 90, qpoints = 315) s3 = Student('G42156', 'Chris Squire', status = 'sophomore', major = 'Musc', enrolled = 'y', credits = 45, qpoints = 160) s4 = Student('G10928', 'Tal wilkenfeld', status = 'junior', major = 'ARTS', enrolled = 'y', credits = 70, qpoints = 225) s5 = Student('G22157', 'Larry Graham', status = 'senior', major = 'CHHS', enrolled = 'y', credits = 105, qpoints = 290) s6 = Student('G31345', 'John Entwistle', status = 'freshman', major = 'CSci', enrolled = 'y', credits = 15, qpoints = 35) s7 = Student('G44568', 'Esperanza Spalding', status = 'junior', major = 'ENGR', enrolled = 'y', credits = 65, qpoints = 250) s8 = Student('G55345', 'Tim Bogert', status = 'sophomore', major = 'Hist', enrolled = 'y', credits = 45, qpoints = 120) s9 = Student('G66113', 'Gordon Sumner', status = 'freshman', major = 'Musc', enrolled = 'y', credits = 15, qpoints = 45) s10 = Student('G11311', 'Paul McCartney', status = 'senior', major = 'ARTS', enrolled = 'y', credits = 110, qpoints = 275) s11 = Student('G22111', 'Elizabeth Smythe', status = 'junior', major = 'ENGR', enrolled = 'y', credits = 85, qpoints = 250) s12 = Student('G31312', 'John McVie', status = 'sophomore', major = 'Hist', enrolled = 'y', credits = 45, qpoints = 120) s13 = Student('G31312', 'Nawt Enrolled', status = 'sophomore', major = 'Hist', enrolled = 'n', credits = 45, qpoints = 120) s14 = Student('G11112', 'Toolow G. Peyay', status = 'freshman', major = 'Undc', enrolled = 'y', credits = 20, qpoints = 38)
print('List of Students created: ') print('s1= ',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, ret values: ', a, b) d1.printRoster() print(' Adding ', s6.name, ' and ', s7.name, ' to ', d2.d_code, ', printRoster follows: ') d2.addStudent(s6) d2.addStudent(s7) d2.printRoster()
print(' Adding ', s8.name, ' and ', s9.name, ' to ', d3.d_code, ', printRoster follows: ') 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() print(' ***** End **********')
In this assignment you are asked to write a Python program to define a class to model some characteristics of a university Department. Specifically, the class will track students requesting to major in that particular department. Students will be represented by student objects created using the Student class developed in A2. When an attempt is made to add the student to a department's major (program), the Department class will examine the Student object data and decide whether to add them to the major. If not, the class returns a response indicating rejection with a short reason why. The Department class should have, at minimum, the following methods (you may add others): Output/returns None See Method Name Purpose Input _init_ Constructor - sets initial attribute values. d_code and d_name are positional attributes, below@@ the others are keyword with default values _str_ Displays a readable version of the Department None object addStudent Adds qualified students to the Department Student object's roster of majors. Uses isQualified object internal method to return whether qualified. is Qualified Returns whether the student is qualified for Student this major. object printRoster Prints a list of Students listed as majoring in None this department's program Department data as a printable string True (added) + 'added' False(not added)+reason True (qualified) or False (not)+reason List of students majoring in department's program @@Attribute d code d name capacity min GPA num_students univ students avgGPA roster Type str str int float int int | float List Definition Department code - 4 char str - valid: {ENGR, ARTS, CHHS Department name - str Maximum number of students allowed to major in the department Incoming student's gpa must be greater than or equal to this Total number of students listed as majors for the Department object Total number of students listed as majors in all departments | Average gpa of all students in department listed as its majors List containing student objects of those majoring in this department Attribute d code d name Type str str Initial value Constructor parm. Constructor parm. ENGR ENGR ARTS ARTS Art and Architecture CHHS CHHS College of Health and Human Services 10 capacity int 5 Set up in init , by deptartment => Set up in init , minGPA float 2.75 2.50 Attribute Type ENGR ARTS CHHS Initial value by department => num students univ students avgGPA roster into int float List 0 None - calculated Empty list
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started