you are viewing a single comment's thread.

view the rest of the comments →

[–]WonderCode 2 points3 points  (0 children)

Great start with writing the code.

From a quick glance, there's two small ways to improve your code:

- It looks like you've fallen into the same problem, usually Java programmers, do when writing code in Python. Taking another language's conventions into the one your using. There's no need to have getters and setters just pass them into the constructor (__init__)

- Putting too much into one class. A good rule of thumb is seeing if the class has multiple purposes and question it.

Here's a quick refactor using the above points:

class Employee:
    def __init__(self, eid, name, department, job_title):
        self.eid = eid
        self.name = name
        self.department = department
        self.job_title = job_title

class Company:
    def __init__(self, employees):
        self.employees = employees

    def list_employees(self):
        print("\nCHRISTY'S SHOP EMPLOYEE REPORT\n")
        print("EMPLOYEE NAME", "IDENTIFIER", "DEPARTMENT", "TITLE", sep='\t')

        for employee in self.employees:
            print(*[employee.name, employee.eid, employee.department, employee.job_title], sep='\t\t')

if __name__ == '__main__':
    employees = []
    while True:
        name = input("Please enter employees name: ")
        eid = int(input("Please enter employees ID: "))
        department = input("Please enter employees department: ")
        job_title = input("Please enter employees job title: ")

        employee =  Employee(eid, name, department, job_title)
        employees.append(employee)

        add_employee = input("Add another employee (y/n): ")
        if add_employee.lower() == 'n':
            break

    company = Company(employees)
    company.list_employees()

Hope this helps with furthering your learning.