Question: Create the following classes: class Employee: Create a default class called Employee. An employee should include seven pieces of information as instance variables: 1 .

Create the following classes:
class Employee:
Create a default class called Employee. An employee should include seven pieces of information as
instance variables:
1. name: the name of the employee
2. id: an automatically generated string based on the year this employee was hired (4 digits)+ this
employee was the __th employee hired (4 digits). For example, the 15th employee of the company
who was hired in 2020 should be 20200015.
3. hire_year: the year that the employee was hired.
4. username: automatically generated string based on the following rules:
a. Get the first character of the employees first name
b. Get the employees entire last name
c. Join them together, and make each character lowercase
d. Add a number at the end based on how many existing usernames that are the same to make sure
that all usernames are unique
For example, if the employees name is David Smith and dsmith,dsmith2, and dsmith3 already
exist, then Davids username should be dsmith4.
5. rank: an integer value in the range of 1 to 10 to show this employees level within the company. The
higher the number is, the higher rank this employee holds.
6. yearly_payment: the employees income for this year.
7. department: an object of the class Department. The department the employee works in.
Also, create a static variable, called employees, a dictionary to store all the employee objects that have
been created. Each employees id should be the key, and the value should be a list with their name,
username, rank, yearly_payment, and department in this order.
An example is given below:
{'2020000': ['Alex Smith', 'asmith0',5,100000, a department object]
'20210001': ['Adam Smith', 'asmith1',4,80000, a department object],
'20210002': ['Allison Smith', 'asmith2',3,75000, a department object],
'20210003': ['Andrew Smith', 'asmith3',0,3, None]}
Tasks:
1. Add constructor. The attributes, name, hire_year, yearly_payment, and rank, must be specified. The
attributes, id and username, are generated automatically. The initial value of the attribute,
department, should be None if not specified.
2. Add a get method for each attribute.
3. Add a set method for the attribute, name.
4. Add a promote() method to promote an employees rank by one. This employees yearly_payment
should also be increased by 10,000 dollars for each promotion.
5. Employee objects should be comparable based on their ranks.
__lt__(self, other) To get called on comparison using < operator.
__le__(self, other) To get called on comparison using <= operator.
__eq__(self, other) To get called on comparison using == operator.
__ne__(self, other) To get called on comparison using != operator.
__ge__(self, other) To get called on comparison using >= operator.
__gt__(self, other) To get called on comparison using > operator.
6. Add a __str__ method to return a string with this employees information: name, id, username, rank,
yearly_payment, and department.
7. You may add some private utility methods to facilitate your design.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!