Answer to Question #245661 in Java | JSP | JSF for James

Question #245661

v> Write a Java programme (named EmployeePay.java) that calculates the weekly

pay for each of your employees based on the total number of hours they have

worked in a week using the following guidelines.

All employees are paid a regular hourly rate of some amount. (Determine

that amount in Ghana cedis)

Indicate the number of regular working hours for all employees in a week

Some employees occasionally work overtime and are supposed to be paid for

the hours they have worked overtime. (Determine the overtime hourly rate in

Ghana cedis. Note: Overtime hourly rate should be more than the regular

hourly rate).

Employees can however only do a maximum of 2 overtime hours each day.

Your programme should work as follows:

i. Create data fields (variables) of the appropriate data types to store all the

variables you will use

ii. When the programme runs, prompt an employee to enter the total

number of hours he/she has worked for the week.




1
Expert's answer
2021-10-02T10:56:13-0400
import java.util.Scanner;


public class EmployeePay {


	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		// The daily minimum wage in Ghana is 11.82 GHS
		final double DAILY_MINIMUM_WAGE = 11.82;
		double regularHourlyRate=DAILY_MINIMUM_WAGE/8.0;
		int numberItemsBrought = -1;


		while (numberItemsBrought < 0 || numberItemsBrought > 50) {
			System.out.print("Enter the totat number of hours employee has worked for the week: ");
			numberItemsBrought = input.nextInt();
			if (numberItemsBrought < 0 || numberItemsBrought > 50) {
				System.out.println("Maximum of 2 overtime hours each day.");
			}
		}
		double weeklyPayEmployee=0;
		if(numberItemsBrought<=40) {
			 weeklyPayEmployee=numberItemsBrought*regularHourlyRate;
		}else {
			 weeklyPayEmployee=40*regularHourlyRate+(numberItemsBrought-40)*regularHourlyRate*1.5;
		}
		System.out.printf("The weekly pay for employee: %.2f\n", weeklyPayEmployee);


		input.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS