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

using Java (include if statements) Paying Employees A company has three differen

ID: 2247675 • Letter: U

Question

using Java (include if statements)

Paying Employees

A company has three different types of employees:

Salaried employees: These employees are paid a yearly salary separated into 52 weekly payments.

Hourly employees: These employees are paid a particular dollar amount per hour of work. These employees are also paid 1.5 times their hour wage for all hours worked above 40 hours.

Production employees: These employees are paid based on the amount of product produced. For example, if the employee is paid $1.25 for each item produced and they produce 100 items, then their pay is $125.00.

Write a program, called wages, that will prompt the user for the employee type, and then based on the employee type, will prompt them for the appropriate information in order to calculate that employee’s weekly pay.

Your program should:

Ask the user for an employee type. Ask them to enter “1" for salaried, “2” for hourly, or “3” for production.

If the user enters a valid employee type, then your program should ask the appropriate questions for that employee to determine the weekly salary:

if the employee is salaried, ask for the yearly salary. Then report the weekly salary.

if the employee is hourly, ask for the pay rate. Then ask for the number of hours worked. Then report the weekly salary. Don’t forget about possible overtime pay!

if the employee is production, ask for the piece good rate. Then ask for the number of pieces made. Then report the weekly salary.

Otherwise, it should state that the user entered an invalid employee type (and do nothing else).

Explanation / Answer

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Sam
*/
public class Wages {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double salary;
        System.out.println("Enter "1" for salaried, "2" for hourly, or "3" for production.");
        int choice = Integer.parseInt(br.readLine());
        switch(choice) {
            case 1:
                System.out.println("What is the yearly salary?");
                salary = (Double.parseDouble(br.readLine()))/52;
                break;
            case 2:
                System.out.println("What is the hourly pay rate?");
                double hourly = Double.parseDouble(br.readLine());
                System.out.println("How many hours worked this week?");
                double hours = Double.parseDouble(br.readLine());
                double overTime = hours - 50 > 0 ? hours - 50:0;
                salary = hours*hourly + overTime*(1.3*hourly); //30% bonus for overtime
                break;
            case 3:
                System.out.println("What is the piece good rate?");
                double rate = Double.parseDouble(br.readLine());
                System.out.println("How many pieces made this week?");
                salary = rate * Double.parseDouble(br.readLine());
                break;
            default:
                System.err.println("the user entered an invalid employee type.");
        }
    }
  
}