need a program to calculate weekly wages for each employee. The user will enter
ID: 3555297 • Letter: N
Question
need a program to calculate weekly wages for each employee. The user will enter the employee's name,
ID.Number, hours worked, and job classification
The job classification of each employee determines the employee's hourly rate. The classifications are as
follows:
Classification Hourly_Rate
1 5.50
2 6.00
3 7.00
4 9.00
5 12.00
When an invalid Classification Type is entered, the hourly rate from classification type 1 is to be used to calculate the employee's wages and an appropriate message is to be printed after the calculated output.
Calculate regular pay: (use a two-way if statement)
? When an employee works the regular number of hours: regular_hours * hourly_rate
? When an employee works more than the regular number of hours: regular_hours * hourly_rate
? When an employee works less than the regular number of hours: hours_worked * hourly_rate
Calculate overtime pay: (use a two-way if statement)
An employee is paid 1.5 times their regular hourly rate for all hours worked over the regular hours, otherwise, the overtime rate is 0.
? When an employee works more than the regular number of hours:
(hours_worked - regular_hours) * 1.5 * hourly_rate
- An appropriate message is to be generated for any employee who works less than 40 hours or more than 60 hours. Examples:
Inadequate number of hours worked! or Excessive number of hours Worked! This message is to be printed after the calculated output. (Use one-way if statements)
Input to this Program:
1. The Employee's Name (First & Last).
2. The Employee's Id. Number.
3. The Employee's Job Classification Number.
4. The Number of Hours Worked.
Output From This Program:
1. All User Input.
2. Number of Overtime Hours.
3. Hourly Rate.
4. Total Amount to be paid to the Employee.
5. Any message that was generated.
Add the code to your payroll program that would allow the user to continue to process employees until the user chooses to stop.
Explanation / Answer
Here's a solution in Java:
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter first name: ");
String fname = sc.next();
System.out.println("Enter last name: ");
String lname = sc.next();
System.out.println("Enter ID number: ");
int id = sc.nextInt();
System.out.println("Enter hours worked: ");
int hours = sc.nextInt();
System.out.println("Enter job classification: ");
int job = sc.nextInt();
int reghours = 60;
double rate = 0;
switch(job){
case 1:
rate = 5.50;
break;
case 2:
rate = 6.00;
break;
case 3:
rate = 7.00;
break;
case 4:
rate = 9.00;
break;
case 5:
rate = 12.00;
break;
default:
rate = 5.50;
}
double pay = 0;
if(hours >= 40 || hours <= 60){
pay = reghours*rate;
}
else{
if(hours > 60){
pay = reghours*rate;
}
else{
pay = hours*rate;
}
}
double ot = 0;
if(hours > reghours){
ot = (hours - reghours)*1.5*rate;
}
String msg = "";
if(hours < 40){
msg += "Inadequate number of hours worked! ";
}
if(hours > 60){
msg += "Excessive number of hours worked! ";
}
System.out.println("Name: "+fname+" "+lname);
System.out.println("Id: " + id);
System.out.println("Job classification number: " + job);
System.out.println("Hours worked: " + hours);
System.out.println("Overtime hours: " + ((hours > 60)?(hours-60):0));
System.out.println("Hourly rate: "+rate);
System.out.println("Total wage: "+(pay+ot));
System.out.println(msg);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.