Create a Person Class that:

a. Accepts First Name
b. Last Name, Age, and Gender
c. Has a method that adds all persons

Create a Student Class that:
a. Inherits the Person Class
b. Accepts GPA
c. Has methods that:

i. Total Number of Male and Female Students.
ii. Average GPA of all Students,
iii. Average Age of the Male and the Female Students

Create a Graduate Class that:

a. Inherits the Student class
b. Accepts Graduation Year, and Job Status (Y or N)
c. Has methods that:
i. Total Number of Male and Female Students of those that have job (override method from Student Class).

Respuesta :

Answer:

See explaination

Explanation:

#Create a person class

class Person:

#Constructor

def __init__(self,firstName,lastName,age,gender):

if firstName=="":

raise Exception('First name should not be empty')

self.firstName=firstName

if lastName=="":

raise Exception('Last name should not be empty')

self.lastName=lastName

if(age<0 or age>100):

raise Exception('Age should be within range 0-100')

self.age=age

if(gender!='M' and gender!='F' and gender!='T'):

raise Exception('Gender should be M/F/T')

self.gender=gender

#Create a student class as a subclass of Person

class Student(Person):

#constructor

def __init__(self,firstName,lastName,age,gender,gpa):

Person.__init__(self,firstName,lastName,age,gender)

if(gpa<0 or gpa>4):

raise Exception('GPA should be 0-4')

self.gpa=gpa

#Function to display graduation status

def gradStatus(self):

print('Getting There!!')

#Create a graduate class as a subclass of Student

class Graduate(Student):

#constructor

def __init__(self,firstName,lastName,age,gender,gpa,gradYear,jobStatus):

Student.__init__(self,firstName,lastName,age,gender,gpa)

if(not gradYear.isdigit()):

raise Exception('Graduation year should be integer')

self.gradYear=gradYear

if(jobStatus!='Y' and jobStatus!='N'):

raise Exception('Job status should be Y/N')

self.jobStatus=jobStatus

#Function to display graduation status

def gradStatus(self):

print('I am Finished!!')

#Function to calculate total graduate student

def totalGraduates(graduate):

return len(graduate)

#Average gpa

def avgGpa(graduate):

sum=0

for grad in graduate:

sum+=grad.gpa

return sum/len(graduate)

#Average age

def avgAge(graduate):

avg=0

count=0

for grad in graduate:

if grad.gender=='M' or grad.gender=='F':

avg+=grad.age

count+=1

return avg/count

#Total Number of Male and Female Graduated Students who have jobs.

def totalJob(graduate):

count=0

for grad in graduate:

if grad.jobStatus=='Y':

count+=1

return count

#Test method

def main():

#Create 5 graduates

graduate=[]

graduate.append(Graduate("Adorn",'Antony',20,'M',3.0,"2011",'Y'))

graduate.append(Graduate("Amelia",'Anus',20,'F',3.5,'2011','Y'))

graduate.append(Graduate("Bambi",'Antony',20,'F',3,'2011','N'))

graduate.append(Graduate("Stephen",'Josh',20,'M',2,'2011','N'))

graduate.append(Graduate("Milli",'Markos',20,'F',4,'2011','Y'))

#Total Number of Graduated Students (use a dunder method to display this).

print('Total Number of Graduated Students: ',totalGraduates(graduate))

#Average GPA of all Graduated Students

print('Average GPA of all Graduated Students: %.2f'%avgGpa(graduate))

#Average Age of the Male and the Female Graduated Students

print('Average age of the Male and the Female Graduated Students: %.2f'%avgAge(graduate))

#Total Number of Male and Female Graduated Students who have jobs.

print('Total Number of Male and Female Graduated Students who have jobs: ',totalJob(graduate))

main()