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

Create an app that calculates payroll. Allow user to enter the number of hours w

ID: 3539307 • Letter: C

Question

Create an app that calculates payroll. Allow user to enter the number of hours worked and hourly wage. The wage should be time and 1/2 for hours worked over 40. Display amount to be paid to the user.

Explanation / Answer

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package payrollprogram; import java.util.Scanner; public class PayrollProgram { /** * @param args the command line arguments */ public static void main(String[] args) { // declare variables String employeeName; double hourlyPay=0; double hoursWorked; double weeklyPay; double overtimeHours; double overtimeRate; double overtimePay; double grossPay; boolean stop = false; //create scanner to imput data java.util.Scanner input = new Scanner(System.in); while (stop == false) { // prompt for employee name or the word stop to exit System.out.print("Please enter the Employee's name or stop to exit the program: "); employeeName=input.nextLine(); if (employeeName.equalsIgnoreCase("stop")) { System.out.print("Exiting Program"); stop = true; break; }// ends if statement else { //prompt for hourly rate System.out.print("Please enter the employee's hourly rate of pay: $"); hourlyPay = input.nextDouble(); }//end else while (hourlyPay < 0) //checks for a negative value { System.out.print("Please enter a positive number: "); hourlyPay = input.nextDouble(); }//end while statement System.out.print("Please enter the number of hours worked for this employee: ");// prompt for number of hours worked hoursWorked = input.nextDouble(); while (hoursWorked < 0)// checks for a negative value { System.out.print("Please enter a positive number: "); hoursWorked = input.nextDouble(); }//end while if (hoursWorked > 40) // determines if employee has overtime { //calculate pay weeklyPay = hoursWorked*hourlyPay; overtimeHours = (hoursWorked - 40); overtimePay = (overtimeHours)*(hourlyPay*1.5); grossPay = weeklyPay+overtimePay; //if employee has overtime display information //System.out.println("Employee: " + employeeName); //System.out.printf("Hourly pay rate: $%.2f ", hourlyPay); //System.out.println("Total number of hours worked: " + hoursWorked); //System.out.printf("Gross pay is : $%.2f ", grossPay); System.out.printf(" %s's", employeeName); System.out.printf(" weekly pay is $%.2f. ",grossPay ); break; }//end if else // if employee does not have overtime display information weeklyPay = hoursWorked*hourlyPay; { //System.out.println("Employee: " + employeeName); //System.out.printf("Hourly pay rate: $%.2f ", hourlyPay); //System.out.println("Total number of hours worked: " + hoursWorked); //System.out.printf("Weekly pay: $%.2f ", weeklyPay); System.out.printf(" %s's", employeeName); System.out.printf(" weekly pay is $%.2f. ",weeklyPay ); break; } }//end while }//end method main }//end class PayrollProgram
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote