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

Design a program WeeklyPay that prompts the user for the name of an employee, th

ID: 3724458 • Letter: D

Question

Design a program WeeklyPay that prompts the user for the name of an employee, the hourly pay, and the hours that the employee worked on each day of the week (M-F). You MUST use a COUNTER-CONTROLLED WHILE LOOP to read in the hours worked for each day (M-F).

An employee earns an overtime rate of time and a half for hours over 40. It is possible that an employee might not work on a week day, but the hours worked for a day cannot be negative. You MUST validate the hours worked entered by the user with an if statement - use zero for a negative value.

Calculate the employee’s pay for the week and display it as currency (2 places past the decimal point). Be sure to label the output. Use the command prompt window (terminal) for input/output.

Create the program, then zip the .java file and upload it. You do NOT need to submit a .class file.  Place your full name in a comment at the top of the file.

Example:

Enter employee's name: Homer Simpson
Enter employee's hourly rate: 19.75

Enter day 1 hours: 8.5
Enter day 2 hours: 9.25
Enter day 3 hours: 8
Enter day 4 hours: 8.25
Enter day 5 hours: 8

Homer Simpson earned $849.25

Explanation / Answer

import java.util.Scanner;


public class WeeklyPay {
public static void main(String args[]) {
String username;
Scanner sc = new Scanner(System.in);
int i = 0;
float hourly_pay = 0;
float no_hours = 0;
float total_hours = 0;
double total_pay = 0;
  
System.out.println("Enter employee's name: ");
username = sc.nextLine();
System.out.println("Enter employee's hourly rate: ");
hourly_pay = sc.nextFloat();
while(i < 5){
System.out.println("Enter day "+ (i+1) + " hours: ");
no_hours = sc.nextFloat();
if(no_hours < 0)
no_hours = 0;
total_hours += no_hours;
i++;
}
if(total_hours >= 40 )
total_pay = (40*hourly_pay) + ((total_hours-40)*hourly_pay*1.5);
else
total_pay = total_hours*hourly_pay;
System.out.println(username + " earned $" + total_pay);
}
}

//Hope this helps :)

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