CS115_Lab07
CS115_Lab07
Lab Guide 07
Lab Objectives: Classes and Inheritance
a) Create a class, Employee, with the following data members and methods. Note all data
members and class variables should be private (__).
Data Members:
● tax_rate: class variable, same for all Employees, which is set to 30%.
● emp_name: string name of the Employee.
● id_num: identification number of the Employee (int).
● wage: the wage of the Employee (float).
Methods:
● __init__():
○ takes an employee name, id number and wage, and using the set
methods, sets the attributes to the given values.
● Get methods for all data members.
● Set methods for all data members implemented according to the following:
○ Employee name must consist of only alphabetic or space characters. If
there is any other character, such invalid characters should be removed.
See the sample run for an example.
○ Id number should be converted to an integer value. If the id number
cannot be converted to an integer, set to the default, 11111111.
○ Wage must be a positive value. If the value is negative, set the wage to
zero.
● calculate_salary(): returns the salary, which is the wage minus the tax
(using tax_rate value)
● __lt__(): an Employee is less than another if their surname is less. If the
surnames are equal, compare the alphabetic first names. Note: You may
assume that all Employees have at least one name, and one surname. The
surname will always be after the final space in the name.
● __eq__() : Employee objects are equal if their id numbers are equal.
● __repr__(): returns a string representation of an Employee object. See the
sample run for formatting.
b) Create a subclass of Employee, Manager, with the following data members and
methods. Note all data members should be private (__).
Data Members:
● bonus: the bonus of the Manager (float).
Methods:
● __init()__: takes the employee name, id number, wage, and bonus.
Calls the Employee init, to initialize the inherited data members, and sets
the bonus to the value passed as a parameter.
● Get method for bonus.
● calculate_salary(): returns the salary of the manager. Managers
make 10% extra salary in addition to the bonus than a regular employee.
They also pay tax at the same rate.
● __repr()__: returns a string representation of a Manager object. The
method should call the Employee __repr__ to get the Employee data, and
append the Manager data, formatted as shown in the sample run.
Sample Run:
Duplicate employee id:
Name: Kemal Oran Employee ID: 87261 Wage: 200000.0
not added
Duplicate employee id:
Name: Veli Sucu Employee ID: 72314 Wage: 350000.0
not added
Sorted List:
[
Name: Ali Aksu Employee ID: 87134 Wage: 280000.0,
Name: Canan Aksu Employee ID: 11111111 Wage: 250000.0,
Name: Hakan Arslan Employee ID: 918236 Wage: 300000.0 Bonus: 600000.0,
Name: Ekrem Bal Employee ID: 87261 Wage: 300000.0,
Name: Zehra Esra Zengin Employee ID: 72314 Wage: 350000.0,
Name: Zeynep Eda Zengin Employee ID: 81214 Wage: 250000.0 Bonus: 500000.0]