106k views
2 votes
(Python) Create a program with a class for Employees that can calculate gross and net weekly pay. The class should have a constructor that takes a first name, last name, and hourly pay rate The class should have a method that takes a number of hours, and returns the weekly gross pay. Assume that hours in excess of 40 are paid at time and a half (1.5 x the hourly rate) The class should have a class variable that holds the income tax rate percentage (initialize to 10). It should also have class methods to get and set that rate. The class should also have a method that takes a number of hours and returns the weekly net pay, which is equal to the weekly gross pay minus the income tax, as per the income tax rate. The main module should ask the user for a first name, last name, and hourly rate. The names should be from 2 to 20 characters in length, and the hourly rate should be reasonable. After getting that data, the main module should instantiate an instance of the Employee class. It should then ask for the number of hours worked during the week, and call the class methods for gross pay and net pay, and should display those amounts.

User VanHoesel
by
8.6k points

1 Answer

2 votes

Final answer:

To create a program with a class for Employees that calculates gross and net weekly pay, follow these steps: create a class, define the constructor, create a method for calculating gross pay, set a class variable for income tax rate, create a method for calculating net pay, and use the class in the main module.

Step-by-step explanation:

In order to create a program with a class for Employees that can calculate gross and net weekly pay, you can follow these steps:

  1. Create a class called Employee with a constructor that takes a first name, last name, and hourly pay rate.
  2. Create a method in the class that takes a number of hours and returns the weekly gross pay. Assume that hours in excess of 40 are paid at time and a half (1.5 x the hourly rate).
  3. Create a class variable that holds the income tax rate percentage and initialize it to 10. Use class methods to get and set that rate.
  4. Create a method in the class that takes a number of hours and returns the weekly net pay, which is equal to the weekly gross pay minus the income tax.
  5. In the main module, ask the user for a first name, last name, and hourly rate, and instantiate an instance of the Employee class with that data.
  6. Ask for the number of hours worked during the week and call the class methods for gross pay and net pay, and display those amounts.
User Milen
by
9.6k points