asked 30.5k views
5 votes
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

1 Answer

0 votes

Final answer:

The Python Employee class should encapsulate the ID, name, and designation of an employee. The ID should be constant throughout the lifecycle of an object, while name and designation should have getter and setter methods. The __str__ method should return a string representation of an employee.

Step-by-step explanation:

Defining a class in Python involves using the keyword class, then indicating the attributes and methods of the object within the class. The Employee class for this hotel scenario should include ID number, name, and designation. The ID number is immutable, so no setter method is needed. The name and designation require getter and setter methods, to provide the ability to change them.

The code might look like:

class Employee:
answered
User Jeremyforan
by
7.7k points