Question

In Python a class can inherit from more than one class (Java does not allow this)....

In Python a class can inherit from more than one class (Java does not allow this). The resulting class will have all the methods and attributes from the parent classes. Do the following:

• Create a class called Person. In the class, define variables for storing date of birth, place of birth, and male/female attributes. In the class, define the constructor method, as well as methods for returning current values of the class attributes.

• Create a class called Employee. In the class, define variables for storing date of hire, department, and job title. In the class, define the constructor method, as well as methods for returning current values of the class attributes.

• Create a class called Salaried that inherits from both Person and Employee classes. In the class define variables for storing the salary and tax bracket. In the class, define the constructor method, as well as methods for returning current values of the class attributes.

• Instantiate a Salaried object using the following attribute default values: Date of birth: January 1, 1980; Place of birth: New York, NY; Male, Date of hire: May 1, 2005, Department: Finance; Job Title: Manager; Salary: 100000; Tax Bracket: 29%.

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

thanks for teh question, here is the complete set of classes in Python.

===================================================================

class Person():
    def __init__(self, dob, pob, gender):
        self.__birthDate = dob
        self.__birthPlace = pob
        self.__gender = gender

    def getBirthDate(self): return self.__birthDate

    def getBirthPlace(self): return self.__birthPlace

    def getGender(self): return self.__gender

    def setBirthDate(self, dob): self.__birthDate = dob

    def setBirthPlace(self, pob): self.__birthPlace = pob

    def setGender(self, gender): self.__gender = gender


class Employee():
    def __init__(self, doh, dep, title):
        self.__hireDate = doh
        self.__department = dep
        self.__jobTitle = title

    def getHireDate(self): return self.__hireDate

    def getDepartment(self): return self.__department

    def getJobTitle(self): return self.__jobTitle

    def setHireDate(self, doh): self.__hireDate = doh

    def setDepartment(self, dep): self.__department = dep

    def setJobTitle(self, title): self.__jobTitle = title


class Salaried(Person, Employee):
    def __init__(self, dob, pob, gender, doh, dep, title, sal, tax):
        Person.__init__(self,dob, pob, gender)
        Employee.__init__(self,doh, dep, title)
        self.__salary = sal
        self.__taxBracket = tax

   def getSalary(self): return self.__salary

    def getTaxBracket(self): return self.__taxBracket

    def setSalary(self, sal): self.__salary = sal

    def setTaxBracket(self, tax): self.__taxBracket = tax


def main():

    john = Salaried('January 1, 1980','New York, NY','Male','May 1, 2005','Finance','Manager',100000,29)
    print('Date of Birth :{}'.format(john.getBirthDate()))
    print('Birth Place:{}'.format(john.getBirthPlace()))
    print('Gender:{}'.format(john.getGender()))
    print('Hire Date:{}'.format(john.getHireDate()))
    print('Department:{}'.format(john.getDepartment()))
    print('Job Title :{}'.format(john.getJobTitle()))
    print('Salary :${}'.format(john.getSalary()))
    print('Tax Bracket :{}%'.format(john.getTaxBracket()))

main()

===================================================================

Add a comment
Know the answer?
Add Answer to:
In Python a class can inherit from more than one class (Java does not allow this)....
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
  • 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...

  • Python In this assignment you are asked to enhance the #3 to define a class to...

    Python In this assignment you are asked to enhance the #3 to define a class to model the characteristics of a generic employee. The class is part of a slightly larger program that incl create some employee objects and test its methods. The name of the class is Employee' and includes the following methods and attributes: n program created in Lab udes code to use the class to Method Name Input/ Attributes Output/ Returns Purpose Constructor sets initial values See...

  • Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person...

    Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Writhe the class definitions, the constructors, and the methods toString for all classes. For Person the constructors should include a no-arg constructor and one that accepts in the name of the person. For student there should be a no-arg constructor and a constructor that accepts...

  • In this laboratory, we are going to build a base class and a collection of derived...

    In this laboratory, we are going to build a base class and a collection of derived classes. Write the code to implement the class Person. A person has a name, address,telephone number and and E-Mail address. Be sure to include accessor functions to return each of these values. Create a derived class Student which has a class status (freshman, sophomore, junior, or senior). Create a derived class Employee which has the attributes office, salary, and date hired. Now define a...

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...

  • 0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY...

    0.Use Factory Design Method 1. Implement an interface called EmployeeInfo with the following constant variables: FACULTY_MONTHLY_SALARY = 6000.00 STAFF_MONTHLY_HOURS_WORKED = 160 2. Implement an abstract class Employee with the following requirements: Attributes last name (String) first name (String) ID number (String) Sex - M or F Birth date - Use the Calendar Java class to create a date object Default argument constructor and argument constructors. Public methods toString - returning a string with the following format: ID Employee number :_________...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

    Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...

  • Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person...

    Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program:   Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

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