Question

PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

PYTHON***************

  • Create a Person Class that:
    • Accepts First Name, Last Name, Age, and Gender
    • Has a method that adds all persons
    • Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class.
  • Create a Student Class that:
    • Inherits the Person Class
    • Accepts GPA
    • Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class.
    • Has methods that:
      • Total Number of Male and Female Students
      • Average GPA of all Students
      • Average Age of the Male and the Female Students
  • Create a Graduate Class that:
    • Inherits the Student class
    • Accepts Graduation Year, and Job Status (Y or N)
    • Validate Graduation Year (integer) and Job Status (Y or N) and throw exception if it does not validate within the class.
    • Has methods that:
      • Total Number of Male and Female Students of those that have job (override method from Student Class).
  • Collect 5 students with their following information:
    • First Name
    • Last Name
    • Gender
    • GPA
    • Age
    • Graduation Year
    • Job Status
  • Display:
    • Total Number of Graduated Students (use a dunder method to display this).
    • Average GPA of all Graduated Students
    • Average Age of the Male and the Female Graduated Students
    • Total Number of Male and Female Graduated Students who have jobs.

Create and note one use of polymorphism with a function in your code program. To do so, create a method in student called GradStatus. Define the GradStatus in Student as “Getting There!!” and GradStatus in Graduate “I am Finished”). also accept student who have not graduated. Based on that, execute the GradStatus method. This can be completed as overriding or as Polymorphism as a function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

#Create a person class class Person: CAWINDOWS\system32\cmd.exe #Constructor Total Number of Graduated students: 5 definit__(Program

#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()

---------------------------------------------

Output

Total Number of Graduated Students: 5
Average GPA of all Graduated Students: 3.10
Average age of the Male and the Female Graduated Students: 20.00
Total Number of Male and Female Graduated Students who have jobs: 3

------------------------------------------------

Note:-

I assume you expect this way

Add a comment
Know the answer?
Add Answer to:
PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a java project and create Student class. This class should have the following attributes, name...

    Create a java project and create Student class. This class should have the following attributes, name : String age : int id : String gender : String gpa : double and toString() method that returns the Student's detail. Your project should contain a TestStudent class where you get the student's info from user , create student's objects and save them in an arralist. You should save at least 10 student objects in this arraylist using loop statement. Then iterate through...

  • Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean)...

    Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean) variables. You have to create constructors and properties for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from a “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the peoples information from “PersonInfo.txt” file and saves them into the array. In C# Give the user the ability to...

  • Write a java program to create a student file which includes first name, last name, and...

    Write a java program to create a student file which includes first name, last name, and GPA. Write another Java program to open the students file. Display the students list and calculate the average GPA of the class.  

  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • Build a java program that has Student class, use arrays of objects {name, age, gpa} to...

    Build a java program that has Student class, use arrays of objects {name, age, gpa} to saves 3 students records. Use printable interface with abstract print method. Student class inherits from an abstract Person class that has name, age as attributes. It also has the following 2 methods: abstract setAge and concrete setGPA. Below is the hierarchy and a sample run (using netbeans): Hierarchy: Printable Interface print(Object ( ) ): object ] Abstract Person Class Name: String Age: int Abstract...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties:...

    Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...

  • PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class...

    PART I: Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes: (1) student ID: protected, an integer of 10 digits (2) student name: protected (3) student group code: protected, an integer (1 for undergraduates, 2 for graduate students) (4) student major: protected (e.g.: Business, Computer Sciences, Engineering) Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()). PART II: Create a Java class named...

  • C++ There is a class called Person which has name and age as private variables. Another...

    C++ There is a class called Person which has name and age as private variables. Another class called Student, which is derived from person with gpa and id as variables. name is a string, age and id are integers and gpa is a double... All of them are private variables. age, gpa and id should be generated randomly when the object is created with the following ranges: age 20 to 32 gpa 0.0 to 4.0 // this one is tricky...

  • a) Create an abstract class Student. The class contains fields for student Id number, name, and...

    a) Create an abstract class Student. The class contains fields for student Id number, name, and tuition. Includes a constructor that requires parameters for the ID number and name. Include get and set method for each field; setTuition() method is abstract. b) The Student class should throw an exception named InvalidNameException when it receives an invalid student name (student name is invalid if it contains digits). c) Create three student subclasses named UndergradStudent, GradeStudent, and StudentAtLarge, each with a unique...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT