3 Replies - 464 Views - Last Post: 28 December 2012 - 10:25 PM Rate Topic: -----

#1 stephenpw  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-December 12

JOptionPane YES_NO Error Help

Posted 28 December 2012 - 06:58 PM

Here is my problem, I'm trying to 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.YES_NO_OPTION;

import javax.swing.*;
import javax.swing.JOptionPane;
public class Pay
{
	public static void main(String[] args)
	{
		String skillLevel;
		String hoursWorked;
		double overtimePay;
		double regularPay;
		int FULL_WEEK = 40;
		final double OT_RATE = 1.5;
		
		double hourlyPay = 0;
		double payRate_1 = 17.00;
		double payRate_2 = 20.00;
		double payRate_3 = 22.00;
		
		String medicalInsurance;
		String dentalInsurance;
		String disabilityInsurance;
		String retirementPlan;
		double insuranceCost = 0;
		double medical = 32.50;
		double dental = 20.00;
		double disability = 10.00;
		boolean isYes;
		
		
			skillLevel = JOptionPane.showInputDialog(null, "What is your skill level? ");
			hoursWorked = JOptionPane.showInputDialog(null, "How many hours did you work this week? ");
			if(skillLevel.equals("1"))
			{
				hourlyPay = payRate_1;
				regularPay = hourlyPay * FULL_WEEK;
				overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
			}
			else
				{
					regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
					overtimePay = 0.00;
				}
			if(skillLevel.equals("2"))
			{
				medicalInsurance = JOptionPane.showInputDialog(null, "Would you like medical insurance? ");
				if(medicalInsurance.equals("Yes"))
				{
					isYes = (Integer.valueOf(medicalInsurance) == JOptionPane.YES_NO_OPTION);
					insuranceCost = medical;
					while(isYes);
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				if(medicalInsurance.equals("No"))
				{
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				
				dentalInsurance = JOptionPane.showInputDialog(null, "Would you like dental insurance? ");
				if(dentalInsurance.equals("Yes"))
				{
					isYes = (Integer.valueOf(dentalInsurance) == JOptionPane.YES_NO_OPTION);
					insuranceCost = dental;
					while(isYes);
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				if(dentalInsurance.equals("No"))
				{
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				
				disabilityInsurance = JOptionPane.showInputDialog(null, "Would you like disability insurance? ");
				if(disabilityInsurance.equals("Yes"))
				{
					isYes = (Integer.valueOf(disabilityInsurance) == JOptionPane.YES_NO_OPTION);
					insuranceCost = disability;
					while(isYes);
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				if(disabilityInsurance.equals("No"))
				{
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
			}		
			if(skillLevel.equals("3"))
			{
				medicalInsurance = JOptionPane.showInputDialog(null, "Would you like medical insurance? ");
				if(medicalInsurance.equals("Yes"))
				{
					isYes = (Integer.valueOf(medicalInsurance) == JOptionPane.YES_NO_OPTION);
					insuranceCost = medical;
					while(isYes);
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				if(medicalInsurance.equals("No"))
				{
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				
				dentalInsurance = JOptionPane.showInputDialog(null, "Would you like dental insurance? ");
				if(dentalInsurance.equals("Yes"))
				{
					isYes = (Integer.valueOf(dentalInsurance) == JOptionPane.YES_NO_OPTION);
					insuranceCost = dental;
					while(isYes);
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				if(dentalInsurance.equals("No"))
				{
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				
				disabilityInsurance = JOptionPane.showInputDialog(null, "Would you like disability insurance? ");
				if(disabilityInsurance.equals("Yes"))
				{
					isYes = (Integer.valueOf(disabilityInsurance) == JOptionPane.YES_NO_OPTION);
					insuranceCost = disability;
					while(isYes);
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				if(disabilityInsurance.equals("No"))
				{
					hourlyPay = payRate_2;
					regularPay = hourlyPay * FULL_WEEK;
					overtimePay = (Integer.valueOf(hoursWorked) - FULL_WEEK) * OT_RATE * hourlyPay;
				}
				else
					{
						regularPay = (Integer.valueOf(hoursWorked)) * hourlyPay;
						overtimePay = 0.00;
					}
				}
			JOptionPane.showMessageDialog(null, "You have a skill level of " + skillLevel + 
			"; you worked " + hoursWorked + " hours this week at " + hourlyPay + " per an hour. Your regular pay is " 
			+ regularPay + " for the week and your overtime pay is " + overtimePay + " for the week. Your total pay is " 
			+ (regularPay + overtimePay) + " dollars for the week minus your chosen insurance cost of " + insuranceCost);  
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: JOptionPane YES_NO Error Help

#2 DaMi25  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 57
  • Joined: 09-December 12

Re: JOptionPane YES_NO Error Help

Posted 28 December 2012 - 08:14 PM

Can you post the whole problem? I'm sorry but I can't understand your code. I want to help.
:)
Was This Post Helpful? 0
  • +
  • -

#3 stephenpw  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-December 12

Re: JOptionPane YES_NO Error Help

Posted 28 December 2012 - 08:59 PM

Sorry, here is the question:
A company runs a small factory. Workers are paid one of the three hourly rates depending on their skill level.

Skill level Hourly rate
1 17
2 20
3 22

Each factory worker might work any number of hours per week; any hour over 40 are paid at one and one-half rate.

In addition workers in skill levels 2 and 3 can choose to participate in the following insurance options:

Option Explanation Weekly Cost to Employee
1) Medical Insurance 32.50
2) Dental Insurance 20
3 Disability Insurance 10

Also, workers in skill level 3 can choose to participate in the retirement plan at 3% of their gross pay.Write an interactive Java payroll application that calculates the net pay for a factory worker.

Write an interactive paroll application that calculates the net pay for a factory worker. The program prompts the user for the skill level and hours worked, as well as appropriate insurance and retirement options for the employees skill level category. The application displays:
1. The hours worked
2. The hourly pay rate
3. The regular pay for 40hours
4. The overtime pay
5. The total of overall and regular time pay
6. Total itemized deduction. If the deductions exceed the gross pay, display an error message; otherwise calculate and display
7. The net pay after all the deductions has been subtracted from the gross.

AMENDMENTS:
• 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.
• Use a do...while() loop to ask the user for their skill level. Keep looping until a valid skill level is provided.
• Use a JOptionPane to show the worker’s gross pay.

MY PROBLEM:

when I type "Yes" to my prompts I receive an error not allowing me to proceed with the other insurance prompts. Here is the error: Exception in thread "main" java.lang.NumberFormatException: For input string: "Yes"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.valueOf(Integer.java:554)
at Pay.main(Pay.java:48)

THANK YOU SO MUCH IF YOU CAN HELP!!!! IF YOU DON'T HEAR BACK FROM ME SOON THEN IT'S BECAUSE I HAVE TO GO TO SLEEP SOON AND WORK TOMORROW SO I'LL RESPOND THEN.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: JOptionPane YES_NO Error Help

Posted 28 December 2012 - 10:25 PM

All your code seems to be over but over complicated to me
However

isYes = (Integer.valueOf(medicalInsurance) == JOptionPane.YES_NO_OPTION);

is completly wrong

How an integer value entered by the user (if the user entered a integer value) can be equal to a JOptionPane constant ? Only by pure hasard I can tell you
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1