Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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:

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

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 List of student objects List of student objects List of student objects Below is the functionality of the required methods. Note that the * _init_ 'method is the same for all Department objects, but the individual instance attributes are given by the code that instantiates (creates) the object. All Departments ENGR-only ARTS-only CHHS-only Method Name init Constructor - initial attribute values. 1. univ_students = 0 (value shared by all objects) 2. capacity and min GPA set up according to department specifications 3. num_students = 0 4. roster = [] 5. avgGPA = not defined until d code = 'ENGR d name= 'Engineering capacity = 5 d code = d code = ARTS' 'CHHS' d_name = 'Art d name= and College of Architecture Health and capacity = 15 Human Services capacity = 10 capacity = 10 str Same method for all Departments addStudent Same method for all Departments 3. num_students = 8 4. roster = [] 5. avgGPA = not defined until students added Displays a readable version of the Department object - code, name, capacity, num students, avgGPA Adds qualified students to the department's roster (list) of majors if qualified. Uses isQualified method to return whether qualified. If qualified: adds student to Dept. roster updates avgGPA updates num_students updates univ_students resets student's major using a newly created Student method returns True + 'added If not added, returns False and a reason for not being added isQualified Same method, Same method, Same method, but uses: but uses: but uses: Internal method that returns whether the student is qualified for this major: Department must be its capacity. The student must be enrolled Uses student sameStudent method to check whether student already listed in the roster - if yes, don't add. GPA > 2.75, currently enrolled, student not already listed GPA > 2.0, student not already listed GPA > 2.5, Currently enrolled, student not already listed Method Name All Departments ENGR-only ARTS-only CHHS-only Checks student has minimum GPA If qualified, returns True+ 'qualified If not qualified, returns False and one of these reasons as an abbreviated char. string: GPA, capacity, duplicate, not enrolled Prints a list of all Students (g_num and Same method for all Departments name) listed as majoring in this department's program. printRoster To create and test the Student class do the following: 1. Create three Department class objects as described above (one per department) and include the Student class from A2 to create student objects. Create a 'setMajor' method for Student so the Department class object can update it when a student object is successfully added to the major. 2. Within the program, use the assignment operator to create and print enough student objects to test and demonstrate the Department class capabilities. Probably 8-12 students are adequate. At least one set should completely fill a department capacity so the 'over capacity' rejection capability can be exercised. 3. Add each of the created students into one of the three Department class objects using the 'addStudent' method 4. Attempt to add a student to a Department object that is already on that Department's roster. 5. Use the printRoster method to display a list of students in that department To test the program copy and paste the code in the IT209_A3_test_script.py (included with the assignment in Blackboard) after your class definitions. That global namespace code will instantiate some Student objects, add them to the Department container class, and exercise various methods to ensure correct execution. Additional tests may be run by the GTA during evaluation for a grade, so merely complying with the test script doesn't ensure a 100% score

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_2

Step: 3

blur-text-image_step3

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

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

ISBN: 0619064625, 978-0619064624

More Books

Students explore these related Databases questions