If the employee is a supervisor calculate her paycheck
as her yearly salary / 52 (weekly pay)
If the employee is not a supervisor and she worked 40 hours or less
calculate her paycheck as her hourly wage * hours worked (regular
pay)
If the employee is not a supervisor and worked more than 40 hours
calculate her paycheck as her (hourly wage * 40 ) + (1 ½ times here
hourly wage * her hours worked over 40) (overtime pay)
This is the original code that I have to convert into an oop. I was given instructions but i'm to the point where i'm overthinking and now i'm lost lol
original code:
input("Employee name:")
t = input("supervisor or employee?")
pay = float(input("What is your hourly rate or yearly
salary?"))
hoursworked = float(input("How many hours did you work this
week(put 0 if salary)?"))
if (t == "supervisor"):
print("Pay this period:$ "), print(pay/52)
elif (hoursworked > 40) :
print("Pay this period:$"),print(float(((hoursworked - 40)*pay*1.5)
+ pay * 40))
else :
print(pay*hoursworked)
New instructions:
Part 1: Employee Class
Create a Python file called employee.py. Include the following in this file.
Create a class called Employee
Constructor that initializes all dependent fields (e.g. name, type, hours worked, etc.)
Getter and Setter methods to set and return each data field
Define at least one function to calculate the regulary pay, overtime pay, and total pay.
Part 2: Supervisor Class
Create a Python file called supervisor.py. Include the following in this file.
Create a class called Supervisor
Constructor that initializes all dependent fields (e.g. name, type, salary, etc.)
Getter and Setter methods to set and return each data field
Define at least one function to calculate the weekly pay.
Part 3: WeeklyPayroll
Create a Python file called weeklypayroll.py. This will be the main Python program. Include the following in this file.
Import both employee.py and supervisor.py modules
Create a main method to start the program
Create functions to read the employee name, employee type
Based on the employee type, instantiate the appropriate employee object and set all required data fields.
Create function(s) to print employee details
The program should also ask if the user wants to add more employees. If yes then continue with the program, otherwise quit the program.
Provide simple validation where necessary to make sure that a valid input is enter, otherwise provide an appropriate message keep prompting the user for a valid input.
Use stepwise refinement and break your solution into several functions as needed. Once again, use what you've already learned and apply them where they fit.
What I have so far:
class Employee :
def __init__(self):
self._name = None
self._type = None
self._hoursWorked = None
self._rate = None
def setName(self,name):
self._name = name
def setType(self,type):
self._type = type
def setHoursWorked(self,hoursWorked):
self._hoursWorked = hoursWorked
def setRate(self,rate):
self._rate = rate
def getName(self):
return self._name
def getType(self):
return self._type
def getHoursWorked(self):
return self._hoursWorked
def getRate(self):
return self._rate
Thank you for helping!
Employee.py
class Employee:
# constructor
def __init__(self, name, type, hoursWorked, rate):
self.__name = name
self.__type = type
self.__hoursWorked = hoursWorked
self.__rate = rate
# setter and getter methods
def setName(self, name):
self.__name = name
def setType(self, type):
self.__type = type
def setHoursWorked(self, hoursWorked):
self.__hoursWorked = hoursWorked
def setRate(self, rate):
self.__rate = rate
def getName(self):
return self.__name
def getType(self):
return self.__type
def getHoursWorked(self):
return self.__hoursWorked
def getRate(self):
return self.__rate
# calculate and return regular pay
def getRegularPay(self):
if self.__hoursWorked > 40:
regular_pay = 40 * self.__rate
else:
regular_pay = self.__hoursWorked * self.__rate
return regular_pay
# calculate and return overtime pay
def getOverTimePay(self):
overtime_pay = 0
if self.__hoursWorked > 40:
overtime_pay = (self.__hoursWorked - 40) * 1.5 * self.__rate
return overtime_pay
# add regular and overtime pay and return
def getTotalPay(self):
total_pay = self.getRegularPay() + self.getOverTimePay()
return total_pay
SCREENSHOT


Supervisor.py
class Supervisor:
# constructor
def __init__(self, name, type, salary):
self.__name = name
self.__type = type
self.__salary = salary
# setter and getter methods
def setName(self, name):
self.__name = name
def setType(self, type):
self.__type = type
def setsalary(self, salary):
self.__salary = salary
def getName(self):
return self.__name
def getType(self):
return self.__type
def getSalary(self):
return self.__salary
# Calculate weekly pay and return
def getWeeklyPay(self):
return self.__salary / 52
SCREENSHOT

WeeklyPayroll.py
# import both the classes
from Employee import *
from Supervisor import *
# this function read data for a employee
def read_data():
name = input("Employee name: ") # input for name
t = input("supervisor or employee? ").lower() # input for type
# validate type. If not valid, ask user to enter again
while t not in ["supervisor", "employee"]:
t = input("supervisor or employee? ").lower()
# input for pay and hoursWorked
pay = float(input("What is your hourly rate or yearly salary? "))
hoursworked = float(input("How many hours did you work this week(put 0 if salary)? "))
# If type is supervisor and hoursWorked is not 0, ask user to ente valid value again
if t == "supervisor":
while hoursworked != 0:
hoursworked = float(input("How many hours did you work this week(put 0 if salary)? "))
else:
emp = Supervisor(name, t, pay) # Else, create object of Supervisor class passing the values
else:
emp = Employee(name, t, hoursworked, pay) # Create object of EMployee class, passing the values
return emp # retunn object emp
def print_employee(emp):
# print name and type
print('Name:', emp.getName())
print('Type:', emp.getType())
if emp.getType() == "supervisor": # if supervisor, print salary and weekly pay
print('Salary:', emp.getSalary())
print('Pay this period:$', emp.getWeeklyPay())
else: # else, print hours worked, rate and pay
print('Hours Worked:', emp.getHoursWorked())
print('Pay Rate:', emp.getRate())
print('Pay this period: $', emp.getTotalPay())
def main():
emp_list = [] # list to store objects
choice = 'y'
while choice.lower() == 'y': # iterate this loop till choice is y
emp = read_data() # call function to read data
emp_list.append(emp) # append emp to list
choice = input('\nDo you want to enter another employee? (y/n) ') # ask if want to enter again
print()
# In a loop, call print_employee function to print every emp
print('Employee Details:')
for emp in emp_list:
print_employee(emp)
print()
if __name__ == '__main__':
main()
SCREENSHOT


OUTPUT

If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly...
THIS IS WHAT I HAVE I NEED TO FIX IT SO:
hours_worked should not be inputed separately.
Get the hours as 40 40 40 40 or 40, 40, 40, 40 whichever
separator suits you.
How do I do this?
How would you change what I have in to it getting into that kind
of input.
Thank you!
class Employee:
again = 'y'
def __init__(self):
self.__rate = 7.25
self.__totalhour = 0
self.__regularpay = 0
self.__overtimepay = 0
self.__totalpay = 0
self.__tax...
A program is needed to compute paychecks for employees. It needs to compute a weekly paycheck based upon the hourly rate and number of hours worked by the employee. Create a class that can be used for this purpose. You simply need to create the class that has attributes and methods that would allow this. It does not need a main() method.
By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...
Design a program(Creating a RAPTOR flowchart) that will read a file of employee records containing employee number, employee name, hourly pay rate, regular hours worked and overtime hours worked. The company pays its employees weekly, according to the following rules: regular pay = regular hours worked × hourly rate of pay overtime pay = overtime hours worked × hourly rate of pay × 1.5 total pay = regular pay + overtime pay Your program is to read the input data...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings. Create another class HourlyEmployee that inherits from the abstract Employee class. HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...
Java
Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...
Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variables - firstN - lastN - idNum -wage: holds how much the person makes per hour -weekHrsWkd: holds how many total hours the person worked each week. - regHrsAmt: initialize to a fixed amount of 40 using constructor. - regPay - otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: -...
1.) Write a code in Python to Calculate weekly pay with overtime for an hourly employee (if number of hours exceed 40, then the hourly rate goes up by 50% of the usual hourly rate; the user will provide the hourly rate and the number of hours worked)
Within c++ Create a simple Employee class with name, department, and title. Create an hourlyEmployee class (which inherits from the Employee class) for a basic payroll program to compute the net pay salary of hourly based employees. Your program should also find the average net pay for a small company. To define the class, include the appropriate data members, member functions, constructors, and access modifiers. For simplicity, use a constant tax rate of 30% to compute the tax amount. Employees...