Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment in Python , you will write a program to simulate a payroll application. To that effect you will also create an Employee

For this assignment in Python, you will write a program to simulate a payroll application. To that effect you will also create an Employee class, according to the specifications below. You will create a linked list of Employee objects to simulate a payroll program.

Specification for Employee class:

Attributes

Employee ID: you can use a string the ID will contain digits and/or hyphens. The ID cannot be changed once an employee object is created.

Number of hours worked in a week: a floating-point number.

Hourly pay rate: a floating-point number that represents how much the employee is paid for one hour of work.

Gross wages: a floating-point number that stores the number of hours times the hourly rate.

Methods

A constructor (__init__)

Setter methods as needed.

Getter methods as needed.

This class should overload the __str__ or __repr__ methods so that Employee objects can be displayed using the print() function.

Specification for Node and LinkedList classes:

You will need to provide an implementation of the Node and the LinkedList classes.

Script

Your main script will simulate a basic payroll system. There should be a menu with the following options:

Add new employee: this option allows you to enter the ID of a new employee and his/her hourly rate.

Calculate Weekly Wages: this option displays each employee ID and asks the user to enter the number of hours worked by each employee. The script should calculate the gross wages for each employee (hours times pay rate) and store the information in the corresponding node.

Display Payroll: this option displays each employees identification number, hours worked, hourly rate, and gross wages.

Update Hourly Rate: this option allows the user update the hourly rate of one employee. The user should enter the ID of the employee. If the ID exits in the list, then the hourly rate can be updated.

Remove Employee for payroll: this option allows the user to remove an employee. The user should enter the ID of the employee. If the ID exits in the list, then the employee can be removed from the list.

Quit the program

You will need a loop to show and process the menu until the user chooses to quit/exit the program.

Validation:

Each employee number should be unique. Do not accept duplicate employee numbers.

Do not accept negative numbers for hours worked.

Do not accept numbers less than 6.00 for pay rate.

Code so far - need to finish main function and validations

class Employee: def __init__(self, id, payRate=0): self.id = str(id) self.numHours = 0 self.payRate = payRate self.grossWages = 0 def setHoursWorked(self, hours): self.numHours = hours self.grossWages = hours * self.payRate def setHourlyRate(self, payRate): self.payRate = payRate self.grossWages = self.numHours * self.payRate def getWages(self): return self.grossWages def __str__(self): return 'Emp: %s, Hours: %d, Wages: $%.2f' % \ (self.id, self.numHours, self.grossWages) class Node: def __init__(self, value: Employee, next_node): self.value = value self.next_node = next_node class LinkedList: def __init__(self, initial=None): self.front = self.back = None def empty(self): if self.front is None: return True else: return False def addEmployee(self): id = input('Enter employee id: ') payRate = float(input('Enter payRate: ')) new = Node(Employee(id, payRate), None) if not self.empty(): self.back.next_node = new self.back = new else: self.front = self.back = new def findEmployeeObject(self, id): current = self.front while current: if current.value.id == id: return current.value else: current = current.next_node return None def calculateWeeklyWages(self): current = self.front while current: id = current.value.id current.value.setHoursWorked(float(input('Enter hours worked by Emp %s: ' % id))) current = current.next_node def displayPayroll(self): current = self.front while current: print(current.value) current = current.next_node def updateHourlyRate(self): id = input('Enter id: ') emp = self.findEmployeeObject(id) if emp is not None: rate = float(input('Enter new hourly rate: ')) emp.setHourlyRate(rate) return else: print('No employee found with id', id) def delete(self, id): if self.front is None: return None if self.front.value.id == id: self.front = self.front.next_node return True prev = self.front current = prev.next_node while current != None: if current.value.id == id: prev.next_node = current.next_node if prev.next_node is None: self.back = prev return True else: prev = current current = current.next_node return False empList = LinkedList() # add 3 employees: empList.addEmployee() empList.addEmployee() empList.addEmployee() print() # update payroll empList.calculateWeeklyWages() print() empList.displayPayroll()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions