Question

The following Java code outputs various amounts for a worker based on skill level, hours worked,...

The following Java code outputs various amounts for a worker based on skill level, hours worked, and insurance:

import java.util.Scanner;
public class Pay
{
public static void main(String[] args)
{
int SkillOneRate = 17;
int SkillTwoRate = 20;
int SkillThreeRate = 22;
double MedicalInsurance = 32.50;
double DentalInsurance = 20.00;
double DisabilityInsurance = 10.00;
int skill,hours;
int choice;
char y;
char n;
int payRate =0;
double regularPay = 0;
double overtimePay = 0;
double grossPay=0;
double deductions=0;
double netPay = 0;
Scanner input = new Scanner(System.in);
System.out.println("Enter skill level: \n1.\n2.\n3.");
skill = input.nextInt();
System.out.println("Ener hours worked: ");
hours = input.nextInt();
if(skill == 1)
{
payRate = SkillOneRate;
}
else
if(skill == 2)
{
payRate = SkillTwoRate;
}
else
if(skill == 3)
{
payRate = SkillThreeRate;
}
  
if(hours>40)
{
regularPay = 40*payRate;
overtimePay = (hours-40)*payRate*1.5;
}
else
{
regularPay = hours*payRate;
grossPay = (regularPay + overtimePay);
}
  
if(skill==2 || skill==3)
{
System.out.println("Enter Insurance: \n1.Medical Insurance\n2.Dental Insurance\n3.Disability Insurance");
int insuranceType = input.nextInt();

if(insuranceType == 1)
{
deductions = MedicalInsurance;
}
else
if(insuranceType == 2)
{
deductions = DentalInsurance;
}
else
if(insuranceType == 3)
{
deductions = DisabilityInsurance;
}

if(skill==3)
{
System.out.println("Retirement Plan with 3% gross pay:\nEnter 1 for yes\nEnter 2 for no");
Scanner input2 = new Scanner(System.in);
choice = input2.nextInt();
if(choice == 1)
{
double retirementCost = grossPay*.03;
deductions = deductions+retirementCost;
grossPay = grossPay-deductions;
}
}   
}

System.out.println("Employee Data:\nHours: " +hours+"\nPay Rate: "+payRate+"\nRegular Pay: "+regularPay+"\nOvertime Pay: "+overtimePay+"\nTotal = Regular + Overtime: "+(regularPay+overtimePay)+"\nDeductions: "+deductions+"\nNet Pay: "+netPay);
}
}

Please make the following three modifications to the code:

1. Use three JOptionPane Confirm Dialog Boxes (using the JOptionPane.YES_NO_OPTION) to ask the worker if they want medical insurance, dental insurance, and long-term disability insurance, as the worker can enroll in more than one insurance option.

2.Use a do...while() loop to ask the user for their skill level. Keep looping until a valid skill level is provided.

3. Use a JOptionPane to show the worker’s gross pay.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import javax.swing.*;


public class Pay
{
    public static void main(String[] args)
    {
        //Declare variables
        final int FULL_TIME_HOURS = 40;
        String skillLevel, hoursWorked;
        int skillLevelInt, medicalInsurance, dentalInsurance, disabilityInsurance,
                retirementPlan = 1;
        boolean validSkillLevel = false, skillLevel3 = false;
        double payRate = 0, regularPay, overtimePay, grossPay, deductionsTotal = 0, netPay,
                hoursWorkedDouble;

        //Skill level prompt loop
        do {
            skillLevel = JOptionPane.showInputDialog(null, "Enter skill level:\n"
                    + "\nSkill Level     Hourly Pay Rate"
                    + "\n    1                  17.00"
                    + "\n    2                  20.00"
                    + "\n    3                  22.00");
            if (skillLevel.equals("1"))
            {
                validSkillLevel = true;
                payRate = 17.00;
            }
            else if (skillLevel.equals("2"))
            {
                validSkillLevel = true;
                payRate = 20.00;
            }
            else if (skillLevel.equals("3"))
            {
                validSkillLevel = true;
                payRate = 23.00;
                skillLevel3 = true;
            }
        }
        while (!validSkillLevel);

        //Hours worked prompt
        hoursWorked = JOptionPane.showInputDialog(null, "Hours worked in week: ");

        //Display insurance options
        if (skillLevel3)
        {
            JOptionPane.showMessageDialog(null,
                    "Option   Explanation                             Weekly cost to employee ($)"
                            + "\n1       Medical Insurance                         $32.50"
                            + "\n2       Dental Insurance                           $20.00"
                            + "\n3       Long-term disability insurance   $10.00"
                            + "\n4       Retirement plan                             %3 of gross pay");
        }
        else
        {
            JOptionPane.showMessageDialog(null,
                    "Option   Explanation                            Weekly cost to employee ($)"
                            + "\n1       Medical Insurance                        $32.50"
                            + "\n2       Dental Insurance                         $20.00"
                            + "\n3       Long-term disability insurance   $10.00");
        }

        //Insurance options prompts  
        medicalInsurance = JOptionPane.showConfirmDialog(null,
                "Choose medical insurance?", "Medical Insurance",
                JOptionPane.YES_NO_OPTION);
        dentalInsurance = JOptionPane.showConfirmDialog(null,
                "Choose dental insurance?", "Dental Insurance",
                JOptionPane.YES_NO_OPTION);
        disabilityInsurance = JOptionPane.showConfirmDialog(null,
                "Choose long-term disability insurance?", "Long-term Disability Insurance",
                JOptionPane.YES_NO_OPTION);
        if (skillLevel3)
        {
            retirementPlan = JOptionPane.showConfirmDialog(null,
                    "Choose retirement plan?", "Retirement Plan",
                    JOptionPane.YES_NO_OPTION);
        }

        //Calculate pay
        hoursWorkedDouble = Double.parseDouble(hoursWorked);
        if (hoursWorkedDouble > FULL_TIME_HOURS)
        {
            overtimePay = (hoursWorkedDouble - FULL_TIME_HOURS) * payRate * 1.5;
            regularPay = FULL_TIME_HOURS * payRate;
        }
        else
        {
            overtimePay = 0;
            regularPay = hoursWorkedDouble * payRate;
        }
        grossPay = regularPay + overtimePay;

        //Calculate Deductions
        if (medicalInsurance == 0)
        {
            deductionsTotal += 32.50;
        }
        if (dentalInsurance == 0)
        {
            deductionsTotal += 20.00;
        }
        if (disabilityInsurance == 0)
        {
            deductionsTotal += 10.00;
        }
        if (retirementPlan == 0)
        {
            deductionsTotal += (grossPay * 0.03);
        }

        netPay = grossPay - deductionsTotal;
        //Display negative net pay error
        if (netPay < 0)
        {
            JOptionPane.showMessageDialog(null,
                    "ERROR: deductions exceed gross pay");
        }
        else
        {

            //Display information
            JOptionPane.showMessageDialog(null, "Your gross pay is: $"
                    + grossPay);

            JOptionPane.showMessageDialog(null, "Detailed Information"
                    + "\nHours worked:     " + hoursWorked
                    + "\nPay rate:              $" + payRate
                    + "\nRegular pay:        $" + regularPay
                    + "\nOvertime pay:      $" + overtimePay
                    + "\nGross pay:            $" + grossPay
                    + "\nTotal deductions:$" + deductionsTotal
                    + "\nNet pay:              $" + netPay);
        }
    }
}

J WorkerPay - [CAUsers Swapnil WorkerPay] - [WorkerPay) - ..src\Pay.java - Intelliu IDEA 2017.1 Eile Edit View Navigate CodeJ WorkerPay - [CAUsers Swapnil WorkerPay] - [WorkerPay) - ..src\Pay.java - Intelliu IDEA 2017.1 Eile Edit View Navigate CodeJ WorkerPay - [CAUsers Swapnil WorkerPay] - [WorkerPay) - ..src\Pay.java - Intelliu IDEA 2017.1 Eile Edit View Navigate Code

Add a comment
Know the answer?
Add Answer to:
The following Java code outputs various amounts for a worker based on skill level, hours worked,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import...

    Must be written in java. Modularize the following code. //CIS 183 Lab 4 //Joseph Yousef import java.util.*; public class SalaryCalc { public static void main(String [] args) { Scanner input = new Scanner(System.in); int sentinelValue = 1; //initializes sentinelValue value to 1 to be used in while loop while (sentinelValue == 1) { System.out.println("Enter 1 to enter employee, or enter 2 to end process: ");    sentinelValue = input.nextInt(); input.nextLine(); System.out.println("enter employee name: "); String employeeName = input.nextLine(); System.out.println("enter day...

  • 1. Need help with a Java application that will compute tip amounts based on user input....

    1. Need help with a Java application that will compute tip amounts based on user input. Please let me know what else my code could use. My code is below and I need help formatting the output and calculating the amount paid by each person. Your application will: ask the user for a restaurant name, a waiter/waitress name, a bill amount and the number of people splitting the bill calculate 10%, 15% and 20% tips on the bill amount calculate...

  • Java Assignment Calculator with methods. My code appears below what I need to correct. What I...

    Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this:     public static double divide(double operand1, double operand2) {         return operand1 / operand2;     } The random method is supposed to return a double within a lower limit and...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in....

    Write Java program( see IncomeTaxClassTemplate) uses a class( TaxTableToolTemplate), which has a tax table built in. The main method prompts for a salary, then uses a TaxTableTools method to get the tax rate. The program then calculates the tax to pay and displays the results to the user. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. a. Modify the TaxTableTools class...

  • My Java code from last assignment: Previous Java code: public static void main(String args[]) { //...

    My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • Write Java program ( see IncomeTaxOverloadClassTemplate) calculates a tax rate and tax to pay given an...

    Write Java program ( see IncomeTaxOverloadClassTemplate) calculates a tax rate and tax to pay given an annual salary. The program uses a class,(see TaxTableToolsOverloadTemplate), which has the tax table built in. Run the program with annual salaries of 10000, 50000, 50001, 100001 and -1 (to end the program) and note the output tax rate and tax to pay. Overload the constructor. Add to the TaxTableTools class an overloaded constructor that accepts the base salary table and corresponding tax rate table...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT