Help! I created the following Java program using the Scanner class, however, I wanted to use the JOptionPane method. How can I convert this to
View the step-by-step solution to:

Question

Help! I created the following Java program using the Scanner class, however, I wanted to use the JOptionPane

method. How can I convert this to JOptionPane? I was also supposed to ask a user if she/he wants to add a medical insurance. If positive, then offer three choices(each of them can be added independently from others) : 1) medical insurance at $50; 2) dental insurance at $25; 3) long term disability at $10. Then deduct the selected insurance(s) from the gross pay. If the deductions exceed the gross pay, display an error message, otherwise display the pay amount to be sent to a user. When a user is not an employee - then I would need to display the proper message on that and terminate the application. Yet I was not able to ever get the program to compile past calculating the gross pay.


import java.util.Scanner;

public class ComputePay

{

public static void main(String[] args)

{

String firstName, lastName;

int anEmployee;

double hourlyPay, hoursWorked, grossPay, taxRate, taxWithheld;

final int YES_EMPLOYEE = 1;

final int NO_EMPLOYEE = 2;

final double FIRST_LIM = 300.00;

final double FIRST_RATE = 0.08;

final double SECOND_LIM = 400.00;

final double SECOND_RATE = 0.10;

final double THIRD_LIM = 500.00;

final double THIRD_RATE = 0.12;

final double FOURTH_LIM = 500.01;

final double FOURTH_RATE = 0.15;

final int MED_CODE = 1;

final int DEN_CODE = 2;

final int LTD_CODE = 3;

final double MED_AMT = 50.00;

final double DEN_AMT = 25.00;

final double LTD_AMT = 10.00;

Scanner inputDevice = new Scanner(System.in);

System.out.print("Please enter your first name >> ");

firstName = inputDevice.nextLine();

System.out.print("Please enter your last name >> ");

lastName = inputDevice.nextLine();

System.out.println("Are you an employee of the company?");

System.out.print("Enter 1 for yes or 2 for no >> ");

anEmployee = inputDevice.nextInt();

if(anEmployee == YES_EMPLOYEE)

{

System.out.print("Enter your hourly pay >> ");

hourlyPay = inputDevice.nextDouble();

System.out.print("Enter your hours worked >> ");

hoursWorked = inputDevice.nextDouble();

grossPay = (hourlyPay * hoursWorked);

if(grossPay <= FIRST_LIM)

taxRate = FIRST_RATE;

else

if(grossPay >= SECOND_LIM)

taxRate = SECOND_RATE;

System.out.println("The Employee's name is " + firstName + lastName);

System.out.println("The Employee's hourly rate is " + hourlyPay);

System.out.println("The Employee worked " + hoursWorked + " hours");

System.out.println("The Employee's gross pay was " + (hourlyPay * hoursWorked));

}

else

{

System.out.println("Sorry user is not an employee");

}

}

}

Top Answer

Following is solution of above... View the full answer

Capture1.JPG

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question