Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The All-Natural Wood Furniture Company has recently hired you to help them conve

ID: 3737882 • Letter: T

Question

The All-Natural Wood Furniture Company has recently hired you to help them convert their manual payroll system to a computer-based system. Write a program to produce a 1-week payroll report for only one employee to serve as a prototype (model) for the administration to review. Input for the system will be the employee’s 4-digit ID number, the employee’s name, hours worked that week, and the employee’s hourly pay rate. Output should consist of the employee’s ID number, the employee’s name, the hours worked that week, the hourly rate, the gross pay, Federal withholding deduction based on an 18% tax rate, State withholding deduction based on a 4.5% tax rate, and net pay.

Use main( ) as the driver function. Allow the user to run the program as many times as desired.

Write 5 functions that main( ) calls to accomplish the task:getData( ): Prompts the user for an employee’s 4-digit ID #, the employee’s name, the hours worked that week, and hourly pay rate. Criteria for data validation:

Employee ID must be an integer between 1000 and 9999, inclusive. Do not allow user to enter an ID number out of this range.

Hours worked must be greater than zero and less than 120. Do not allow user to enter the amount of hours worked outside of this range.

Hourly Rate must be greater than zero. Do not allow the user to enter a zero or a negative pay rate.

computeGrossPay( ): Computes gross pay earned by employee. An employee working more than 40 hours per week is compensated at time-and-a-half for every hour over 40.

computeDeductions( ): Computes the Federal and State withholding deductions using the rates listed above.

computeNetPay( ):   Calculates the net pay for the employee.

displayResults( ): Displays the employee’s ID#, the employee’s name, the hours worked, the hourly pay rate, gross pay, Federal withholding amount, State withholding amount, and Net Pay.

Sample Input/Output:

Please enter the employee's 4 digit ID # and press <Enter>

1468

Please enter the employee’s name:

Mary Jones

Please enter the amount of hours worked this week and press <Enter>

36

Please enter the hourly pay rate for this employee and press <Enter>

7.5

Employee ID:                            1468

Employee Name:                       Mary Jones

Hours Worked:                          36.00 hours

Hourly Rate:                              $      7.50

Gross Pay:                                 $    270.00

Deductions:  

    Federal Withholding:            $      48.60

    State Withholding:                $      12.15

    NET PAY:                             $     209.25

Would you like to calculate the net pay of another employee? Y or N y

Please enter the employee's 4 digit ID # and press <Enter>

5634

Please enter the employee's name: Lucy Smith

Please enter the amount of hours worked this week and press <Enter>

8978

ERROR: INVALID AMOUNT OF HOURS WORKED!

Please enter the amount of hours worked this week and press <Enter>

4566

ERROR: INVALID AMOUNT OF HOURS WORKED!

Please enter the amount of hours worked this week and press <Enter>

42

Please enter the hourly pay rate for this employee and press <Enter>

-9

ERROR: INVALID Pay Rate!

Please enter the hourly pay rate for this employee and press <Enter>

12.5

Employee:                                       5634

Employee Name:                             Lucy Smith

Hours Worked:                                42.00 hours

Hourly Rate:                                    $     12.50

Gross Pay:                                       $    537.50

Deductions:  

    Federal Withholding:                  $     96.75

    State Withholding:                      $     24.19

    NET PAY:                                   $    416.56

Would you like to calculate the net pay of another employee? Y or N n

Explanation / Answer

import java.util.*;

import java.util.Scanner;

class Company{

//Declaring Member Variables private because to achieve Encapsulations!

private int id_num;

private String emp_name;

private double hour_work;

private double hour_pay;

private double gross_pay;

private static final double fedral_tax=0.18;//18%=18/100 Constant Value

private static final double state_tax=0.045;//4.5%=4.5/100 Constant Value

private double federal;

private double state;

private double net_amount;

public int getData0(int n)

{

int temp=n;

int r=0;

while(temp!=0){ //Verifies 4 digit

temp = temp/10;

r++;

}

if(r==4){

if(n>=1000&&n<=9999){

id_num = n;

}

else{

System.out.println("Not in Range");

}

}

else{

return -1;

}

return 0;

}

public void getData1(String s){

emp_name = s;

}

public int getData2(double hw){

if(hw>0&&hw<120){

hour_work = hw;

}

else

return -1;

return 0;

}

public int getData3(double hp){

if(hp>0){

hour_pay = hp;

}

else

return -1;

return 0;

}

public void computeGrossPay(){

int gross=0;

gross_pay = hour_work*hour_pay;

if(hour_work>40){

double i6 = hour_work-40.00;

gross_pay = (i6*hour_pay)/2+gross_pay;

}

}

public void computeDeductions(){

federal = gross_pay*fedral_tax;

state = gross_pay*state_tax;

}

public void computeNetPay(){

net_amount = gross_pay-(federal+state);

}

public void dispalyResuults(){

System.out.println("Employee ID: "+id_num);

System.out.println("Employee Name: "+emp_name);

System.out.println("Hours Worked: "+hour_work+" hours");

System.out.println("Hourly Rate: $ "+hour_pay);

System.out.println("Gross Pay: $ "+gross_pay);

System.out.println(" ");

System.out.println(" ");

System.out.println("Deductions:");

System.out.println(" Federal Withholding: $ "+federal);

System.out.println(" State Withholding: $ "+state);

System.out.println(" ");

System.out.println(" ");

System.out.println(" NET PAY: $ "+net_amount);

}

};

public class TestCompany{

public static void main(String[] args){

int k, r, v, l=0, confirm=1;

String t, s1="y";

Company c = new Company();

Scanner s = new Scanner(System.in);

while(confirm>0){

for(int i=0; i<4; i++){

switch(i){

case 0:

System.out.println("Please enter the employee's 4 digit ID# and press<Enter>");

int i1 = s.nextInt();

k = c.getData0(i1);

if(k==-1){

System.out.println("Enter Proper ID");

i--;

break;

}

else

break;

case 1:

System.out.println("Please enter the employee's name:");

s.nextLine();

String i2 = s.nextLine();

c.getData1(i2);

break;

case 2:

System.out.println("Please enter the amount of hous worked this week and press<Enter>");

double i3 = s.nextDouble();

r = c.getData2(i3);

if(r==-1){

System.out.println("ERROR: INVALID AMOUNT OF HOURS WORKED!");

i--;

break;

}

else

break;

case 3:

System.out.println("Please enter the hourly pay rate for this employee and press<Enter>");

double i4 = s.nextDouble();

v = c.getData3(i4);

if(v==-1){

System.out.println("ERROR: INVALID Pay Rate!");

i--;

break;

}

else

break;

default: break;

}

}

c.computeGrossPay();

c.computeDeductions();

c.computeNetPay();

c.dispalyResuults();

System.out.print("Would you like to calculate the net pay of another employee?Y or N ");

s.nextLine();

t = s.nextLine();

int i5 = s1.compareTo(t.toLowerCase());

if(i5==0){

String []y = {"y"};

main(y);

}

else{

System.exit(0);

}

}

}//main exit

};//TestCompany class exit