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

Step 2: Use the code above to do the following:

image text in transcribedimage text in transcribedimage text in transcribed

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 Method Name Purpose Input _init_ Constructor - sets initial attribute values. See 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 is Qualified 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 minGPA 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 The following table shows the allowed values for each of the three Department objects: Attribute d_code d name Type str str Initial value Constructor parm. Constructor parm. ENGR ENGR Engineering ARTS ARTS Art and Architecture 15 CHHS CHHS College of Health and Human Services 10 capacity int Set up in init , by deptartment => Set up in init , minGPA float 2.75 2.0 2.50 Attribute Type ENGR ARTS CHHS num students univ_students avgGPA roster int int float List Initial value by department => 0 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-onlyCHHS-only Method Name init d_code = 'ENGR' d_name= 'Engineering capacity - 5 d_code = 'ARTS d name = 'Art and Architecture capacity = 15 d_code = 'CHHS' d name= "College of Health and Human Services capacity = 10 str Same method for all Departments addStudent Constructor - initial attribute values. 1. univ students = 0 (value shared by all objects) 2. capacity and minGPA set up according to department specifications 3. num_students = 0 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 i 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 Same method for all Departments isQualified Same method, Same method, but uses: but uses: Same method, but uses: Internal method that returns whether the student is qualified for this major: Department must be 2.75, currently enrolled, student not already listed GPA > 2.0, student not already listed GPA>2.5, Currently enrolled, student not already listed All Departments Method Name 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 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 Method Name Purpose Input _init_ Constructor - sets initial attribute values. See 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 is Qualified 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 minGPA 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 The following table shows the allowed values for each of the three Department objects: Attribute d_code d name Type str str Initial value Constructor parm. Constructor parm. ENGR ENGR Engineering ARTS ARTS Art and Architecture 15 CHHS CHHS College of Health and Human Services 10 capacity int Set up in init , by deptartment => Set up in init , minGPA float 2.75 2.0 2.50 Attribute Type ENGR ARTS CHHS num students univ_students avgGPA roster int int float List Initial value by department => 0 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-onlyCHHS-only Method Name init d_code = 'ENGR' d_name= 'Engineering capacity - 5 d_code = 'ARTS d name = 'Art and Architecture capacity = 15 d_code = 'CHHS' d name= "College of Health and Human Services capacity = 10 str Same method for all Departments addStudent Constructor - initial attribute values. 1. univ students = 0 (value shared by all objects) 2. capacity and minGPA set up according to department specifications 3. num_students = 0 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 i 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 Same method for all Departments isQualified Same method, Same method, but uses: but uses: Same method, but uses: Internal method that returns whether the student is qualified for this major: Department must be 2.75, currently enrolled, student not already listed GPA > 2.0, student not already listed GPA>2.5, Currently enrolled, student not already listed All Departments Method Name 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

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: 3

blur-text-image

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

Request for Proposal is often abbreviated as _ _ _ _ .

Answered: 1 week ago