In: Computer Science
import java.util.Scanner;
public class Payroll {
public static void main(String[] args) {
Scanner readData = new Scanner (System.in);
While{
System.out.print("press the "?" key to stop and exit: ");
char key =
readData.nextChar();
if (key == "?")
// This is how we break out of the loop. Processing "ESC" key
involves more code
break;
//Let's gather
employee data
System.out.print("Enter employee's ID number: ");
int empID =
readData.nextInt();
System.out.print("Enter employee's name: ");
String name =
readData.nextLine();
System.out.print("Enter number of hours worked in the current week:
");
int hours =
readData.nextInt();
System.out.print("Enter hourly wage: ");
double wage =
readData.nextDouble();
System.out.print("Enter % federal tax rate without the % sign:
");
int fedRate =
readData.nextInt();
System.out.print("Enter % state tax rate without the % sign:
");
int stateRate =
readData.nextInt();
//let's compute
deduction, overtime payment, gross pay and net pay
if (hours <=
40)
double grossPay = hours * wage;
else
double grossPay = (hours-40)* 2 * wage + 40 *
wage;
double
fedTaxDeduction = ((fedRate/100.0) * grossPay);
double
stateTaxDeduction = ((stateRate/100.0) * grossPay);
double netPay =
grossPay - fedTaxDeduction - stateTaxDeduction;
//let's format
netPay to two decimal places
netPay =
(int)(netPay * 100)/100.0;
//print
payroll
System.out.println("\n\nEmployee Id: " + empID);
System.out.println("\n\nEmployee Name: " + name);
System.out.println("Hours Worked: " + hours);
System.out.println("hourly wage: $" + wage);
System.out.println("Gross Pay: $" + grossPay);
System.out.println(" Federal tax (" + (double)fedRate + "%): $" +
FedTaxDeduction);
System.out.println(" State tax (" + (double)stateRate + "%): $" +
stateTaxDeduction);
System.out.println("Net Pay: $" + netPay);
} do
}
}