Using Java write a program that allows a user to calculate the weekly employee p
ID: 3869803 • Letter: U
Question
Using Java write a program that allows a user to calculate the weekly employee pay for a company.
The program will have a loop that runs until the user signals it to stop.
Each run of the loop, enter the hours a given employee has worked this week, and their pay-rate. Do not allow a value less than $7.25 to be assigned to pay-rate. Do not allow a value less than zero to be assigned to the hours worked this week. If either of the above errors occur, prompt the user to enter a valid value. Keep prompting them until they enter acceptable values.
Once the program has acceptable data, calculate and display that employees weekly pay. If they have worked more than 40 hours, give them overtime pay for the extra hours. Overtime pay is one-and-a-half times regular pay.
When the user is done entering the weekly pay information, a running total amount (the pay for all employees) should display.
Explanation / Answer
EmloyeePay.java
import java.util.Scanner;
public class EmloyeePay {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double totalPay = 0;
char ch = 'y';
while(ch !='q') {
System.out.println("Enter the employee hours worked: ");
int hours = scan.nextInt();
while(hours < 0) {
System.out.println("Invalid hours. Hours should be greater than or equal 0.");
System.out.println("Enter the employee hours worked: ");
hours = scan.nextInt();
}
System.out.println("Enter the pay rate: ");
double payRate = scan.nextDouble();
while(payRate <= 7.25) {
System.out.print("Invalid pay rate. Pay rate should be greater than or equals to 7.25.");
System.out.println("Enter the pay rate: ");
payRate = scan.nextDouble();
}
double weeklyPay = 0;
if(hours > 40) {
weeklyPay = (hours-40)*1.5*payRate;
hours = 40;
}
weeklyPay = weeklyPay + payRate * hours;
System.out.println("Employee Weekly Pay: "+weeklyPay);
totalPay += weeklyPay;
System.out.println("Do you want to continue(q to Quit or press any key): ");
ch = scan.next().charAt(0);
}
System.out.println("Total amount for all employee: "+totalPay);
}
}
Output:
Enter the employee hours worked:
55
Enter the pay rate:
7.7
Employee Weekly Pay: 481.25
Do you want to continue(q to Quit or press any key):
e
Enter the employee hours worked:
66
Enter the pay rate:
5.5
Invalid pay rate. Pay rate should be greater than or equals to 7.25.Enter the pay rate:
8.8
Employee Weekly Pay: 695.2
Do you want to continue(q to Quit or press any key):
q
Total amount for all employee: 1176.45
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.