Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

JOptionPane YES_NO Error Help

$
0
0
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);  
	}
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>