QUESTION 1:
This question is also to be used for the next question.
Design an Employee class for a hotel for use in programs. We need an Employee object with these attributes:
Name
Designation (ex. Manager, Supervisor, Waiter, Bellhop, etc.)
ID number
Some details:
ID Numbers should already be known at time of object's creation. Assume it is an 8 digit number.
The ID Number can never be changed
Use strings to represent the Name and Designation
It is possible to change an employee's Name and Designation
Be sure to provide a __str__ method that prints a description of the employee
Design and implement this class. Be sure to include an appropriate constructor ( __init__ ) and getter and setter methods where needed.
There will potentially be some design decisions for you to make.
QUESTION 2:
Please refer to the prior question to answer this one.
Based in you class definition and implementation for the Employee class, write lines of code to fully test all methods of your class. This would be a main type of program.
ANSWER :-
GIVEN THAT :-
class Employee:
id_number=None
def __init__(self,name,designation,id_number):
self.name=name
self.designation=designation
Employee.id_number=id_number#cannot be changed through object
def __str__(self):
print("Employee Details")#print the details of Employee
print("Name:",self.name)
print("Designation:",self.designation)
print("ID Number:",Employee.id_number)
return " "
def getName(self):#getter and setter methods
return self.name
def setName(self,n):
self.name=n
def getDesignation(self):
return self.designation
def setDesignation(self,d):
self.designation=d
def getID(self):
return Employee.id_number
e=Employee("n1","d1",121345678)
print(e)
SCREEN SHOT :-
OUTPUT :-
Get Answers For Free
Most questions answered within 1 hours.