In: Computer Science
The program you will be writing displays a weekly payroll report. A loop in the program should ask the user for the employee's number, last name, worked hours, hourly pay rate, state tax and federal tax rate. After data in entered and the user hits the enter key, the program will calculate gross an net pay, then displays all employee's payroll information, and ask for the next employees' information. if worked hour is more than 40, double pay the hours worked more than 40 hours.
In the program, after done first employee, display "would you like to enter next employee's information?"
if the user type "y", "Y", "YES", "Yes", "YEs", "yES", "yeS", the program should prompt for second employee info entry.
if the user type "n", "N", "No","NO", nO", "no", the program should exit.
Need the code in Java (I have struggle in the big loop when asking input second employee's info or not).
If you have any doubts, please give me comment...
import java.util.Scanner;
public class WeeklyPayroll{
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String empNumber, lname, response;
double worked_hours, hourly_pay_rate, state_tax_rate, federal_tax_rate, taxes;
double gross_pay, net_pay;
do{
System.out.print("Enter employee number: ");
empNumber = scnr.next();
System.out.print("Enter employee lastname: ");
lname = scnr.next();
System.out.print("Enter employee worked hours: ");
worked_hours = scnr.nextDouble();
System.out.print("Enter employee hourly pay rate: ");
hourly_pay_rate = scnr.nextDouble();
System.out.print("Enter state tax: ");
state_tax_rate = scnr.nextDouble();
System.out.print("Enter federal tax: ");
federal_tax_rate = scnr.nextDouble();
gross_pay = worked_hours*hourly_pay_rate;
if(worked_hours>40)
gross_pay += (worked_hours-40)*hourly_pay_rate;
taxes = gross_pay*(state_tax_rate/100) + gross_pay*(federal_tax_rate/100);
net_pay = gross_pay + taxes;
System.out.println("\nEmployee Number: "+empNumber);
System.out.println("Last Name: "+lname);
System.out.println("Worked hours: "+worked_hours);
System.out.println("Hourly Pay rate: "+hourly_pay_rate);
System.out.println("Gross Pay: $"+gross_pay);
System.out.println("Tax: $"+taxes);
System.out.println("Net Pay: $"+net_pay);
System.out.print("\nwould you like to enter next employee's information? ");
response = scnr.next();
}while(response.equalsIgnoreCase("yes") || response.equalsIgnoreCase("y"));
}
}