Write a Java application that inputs an unknown number of employees and determin
ID: 3831377 • Letter: W
Question
Write a Java application that inputs an unknown number of employees and determines and displays the gross pay for each employ. The company pays straight time for the first 40 hours worked by each employee (hours times rate), and straight time plus time-and-a-half for all hours worked in excess of 40 hours. Input the number of hours worked and hourly rate for each of the employees, then determine and display the employee’s gross pay. At the end of the program, print the total gross pay for all employees
only Sentinel Control Algorithm... Text Pad please. thank You
Explanation / Answer
package org.students;
import java.util.Scanner;
public class CalEmpGrossPay {
public static void main(String[] args) {
//Declaring constant
final int SENTINEL=-1;
//Declaring variables
int no_of_hours;
double payrate,emp_grossPay=0.0,total_grossPay=0.0;
//Scanner object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
//getting no of hours worked by an employee
System.out.print("No of hours Worked (-1 to Exit) :");
no_of_hours=sc.nextInt();
/* This loop continues to execute until
* the user enters a SENTINEL
*/
while(no_of_hours!=SENTINEL)
{
//Getting the Payrate entered by the user
System.out.print("Enter Pay Rate :$");
payrate=sc.nextDouble();
//calculating the gross pay of an Employee based on no of hours worked
if(no_of_hours<=40)
{
emp_grossPay=no_of_hours*payrate;
total_grossPay+=emp_grossPay;
}
else if(no_of_hours>40)
{
emp_grossPay=(40*payrate)+(no_of_hours-40)*payrate*1.5;
total_grossPay+=emp_grossPay;
}
System.out.println("Employee Gross Pay :$"+emp_grossPay);
System.out.print(" No of hours Worked (-1 to Exit) :");
no_of_hours=sc.nextInt();
}
//calculating the gross pay of all employees
System.out.println(" Total Gross Pay of all Employees :$"+total_grossPay);
}
}
___________________
Output:
No of hours Worked (-1 to Exit) :48
Enter Pay Rate :$12
Employee Gross Pay :$624.0
No of hours Worked (-1 to Exit) :39
Enter Pay Rate :$10
Employee Gross Pay :$390.0
No of hours Worked (-1 to Exit) :42
Enter Pay Rate :$8
Employee Gross Pay :$344.0
No of hours Worked (-1 to Exit) :52
Enter Pay Rate :$9
Employee Gross Pay :$522.0
No of hours Worked (-1 to Exit) :-1
Total Gross Pay of all Employees :$1880.0
_______________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.