Apr-30-2024, 03:18 PM
(This post was last modified: Apr-30-2024, 03:19 PM by deanhystad.)
You do not save enough information in the csv file. There is no way to differentiate between commissioned and hourly employees. I would save all five employee fields PLUS a field identifying the employee wage type ("salary", "commission", "hourly"). This will make it easy to determine what class to use when loading employee data from the file.
All that code in main() should be part of PayrollSystem. I would expect main() to look more like this:
print("Invalid selection.")
PayrollSystem should have the brains and the most main needs to do is provide a way to call the methods provided by the PayrollSystem.
Your Employee classes are backward. Your subclasses do most of the work, and the base class does almost nothing. Your base class should do most of the work, and the subclasses do only the parts that are specific to that class. The more work you can push up from subclasses to parent classes, the better the design (usually). As an example, the following method could be added to the Employee class and used to calculate pay for any employee.
All that code in main() should be part of PayrollSystem. I would expect main() to look more like this:
def main(): payroll = PayrollSystem() payroll.restore() # Restore from file at startup. while True: print("Options\n(1) Add employees\n(2) Print payroll\n(3) Quit") match input("Enter: "): case "1": payroll.add_employee() # Add 1 employee payroll.save() # Save updated employee list. case "2": payroll.print() case "3": breakcase _:
print("Invalid selection.")
PayrollSystem should have the brains and the most main needs to do is provide a way to call the methods provided by the PayrollSystem.
Your Employee classes are backward. Your subclasses do most of the work, and the base class does almost nothing. Your base class should do most of the work, and the subclasses do only the parts that are specific to that class. The more work you can push up from subclasses to parent classes, the better the design (usually). As an example, the following method could be added to the Employee class and used to calculate pay for any employee.
def pay(self): """Calculate employee pay.""" return self.salary + self.commission + self.rate * self.hoursSalaried employees will have 0 for commission, rate and hours. Hourly employees will have 0 for salary and commission.