Results 1 to 2 of 2
  1. #1
    gabrielpr12 is offline Member
    Join Date
    Nov 2011
    Posts
    41
    Rep Power
    0

    Default Getting a couple of errors on Payroll application

    Trying to get this thing working correctly. Need a program that calculates the pay of an employee. I first need to get the employee's skill level, which will determine his pay rate. Then need to get how many hours the employee worked, if more than 40 then pay overtime. Next, if the employee is skill level 2 or 3, ask him for insurance options. Last, if skill level 3, then ask if he would like to participate in a retirement plan at 3% of his gross pay. I am getting there with the code, but I am having some errors. First if the user inputs 1 as the skill level, the program stops right after he enters the hours worked. Another error is that I don't know how to add and subtract using the variable name. For example if I want to add regularPay + overtime and then subtract insurance. Any help will be appreciated. Here is my code:

    Java Code:
    import java.util.*;
    import javax.swing.*;
    
    public class Pay3
    {
    	public static void main(String[] args)
    	{
    		int choice;
    		choice = 0;
    		double retirement;
    		double insurance;
    		insurance = 0;
    		double rate;
    		rate = 0;
    		int option;
    		double hoursWorked;
    		double regularPay;
    		double overtimePay;
    		int skillLevel;
    		final int FULL_WEEK = 40;
    		final double OT_RATE = 1.5;
    		Scanner keyboard = new Scanner(System.in);
    		
    		System.out.print("What is your skill level?");
    		skillLevel = keyboard.nextInt();
    		if(skillLevel == 1)
    			rate = 17.00;
    			else
    				if(skillLevel == 2)
    					rate = 20.00;
    				else
    					if(skillLevel == 3)
    						rate = 22.00;
    		else
    			System.out.println("Invalid skill level.");
    		
    		System.out.print("How many hours did you work this week?");
    		hoursWorked = keyboard.nextDouble();
    		if(hoursWorked > FULL_WEEK)
    		{
    			regularPay = FULL_WEEK * rate;
    			overtimePay = (hoursWorked - FULL_WEEK) * OT_RATE * rate;
    		}
    		else
    		{
    		
    			regularPay = hoursWorked * rate;
    			overtimePay = 0.0;
    		}
    		
    		if(skillLevel == 2 || skillLevel == 3)
    			System.out.println("Choose your insurance options:");
    			option = keyboard.nextInt();
    			if(option == 1)
    				insurance = 32.50;
    				if(option == 2)
    					insurance = 20.00;
    					if(option == 3)
    						insurance = 10.00;
    						if(option == 1 && option == 2)
    							insurance = 52.50;
    							if(option == 1 && option == 3)
    								insurance = 42.50;
    								if(option == 2 && option == 3)
    									insurance = 30.00;
    			else
    				if(skillLevel == 1)
    				insurance = 0;
    		if(skillLevel == 3)
    			System.out.println("Would you like to participate in thge retirement plan?");
    			choice = keyboard.nextInt();
    			if(choice == 1)
    				retirement = 0.03;
    			else
    				retirement = 0;
    		System.out.println("Regular pay is " +
    			regularPay + "\nOvertime pay is " + overtimePay + "\nHours worked: " + hoursWorked +
    			"\nYour hourly rate is: " + rate + "\nTotal gross pay is: " + (regularPay + overtimePay) +
    			"\nYour total deductions are: " + insurance + "\nYour net pay is: " + 
    			regularPay +
    			overtimePay);
    	}
    	
    }

  2. #2
    gabrielpr12 is offline Member
    Join Date
    Nov 2011
    Posts
    41
    Rep Power
    0

    Default Re: Getting a couple of errors on Payroll application

    I was able to fix the adding and subtracting problem. But I am still having problems when the user chooses skill level 1. How can I fix this? Here is the updated code:
    Java Code:
    import java.util.*;
    import javax.swing.*;
    
    public class Pay3
    {
    	public static void main(String[] args)
    	{
    		int choice;
    		choice = 0;
    		double retirement;
    		double insurance;
    		double totalPay;
    		insurance = 0;
    		double rate;
    		rate = 0;
    		int option;
    		double hoursWorked;
    		double regularPay;
    		double overtimePay;
    		double netPay;
    		int skillLevel;
    		final int FULL_WEEK = 40;
    		final double OT_RATE = 1.5;
    		Scanner keyboard = new Scanner(System.in);
    		
    		System.out.print("What is your skill level?");
    		skillLevel = keyboard.nextInt();
    		if(skillLevel == 1)
    			rate = 17.00;
    			else
    				if(skillLevel == 2)
    					rate = 20.00;
    				else
    					if(skillLevel == 3)
    						rate = 22.00;
    		else
    			System.out.println("Invalid skill level.");
    		
    		System.out.print("How many hours did you work this week?");
    		hoursWorked = keyboard.nextDouble();
    		if(hoursWorked > FULL_WEEK)
    		{
    			regularPay = FULL_WEEK * rate;
    			overtimePay = (hoursWorked - FULL_WEEK) * OT_RATE * rate;
    		}
    		else
    		{
    		
    			regularPay = hoursWorked * rate;
    			overtimePay = 0.0;
    		}
    		
    		if(skillLevel == 2 || skillLevel == 3)
    			System.out.println("Choose your insurance options:");
    			option = keyboard.nextInt();
    			if(option == 1)
    				insurance = 32.50;
    				if(option == 2)
    					insurance = 20.00;
    					if(option == 3)
    						insurance = 10.00;
    						if(option == 1 && option == 2)
    							insurance = 52.50;
    							if(option == 1 && option == 3)
    								insurance = 42.50;
    								if(option == 2 && option == 3)
    									insurance = 30.00;
    			else
    				if(skillLevel == 1)
    				insurance = 0;
    		if(skillLevel == 3)
    			System.out.println("Would you like to participate in thge retirement plan?");
    			choice = keyboard.nextInt();
    			if(choice == 1)
    				retirement = 0.03;
    			else
    				retirement = 0;
    			totalPay = regularPay + overtimePay;
    			netPay = totalPay - insurance;
    		System.out.println("Regular pay is " +
    			regularPay + "\nOvertime pay is " + overtimePay + "\nHours worked: " + hoursWorked +
    			"\nYour hourly rate is: " + rate + "\nTotal gross pay is: " + (regularPay + overtimePay) +
    			"\nYour total deductions are: " + insurance + "\nYour net pay is: " + netPay);
    	}
    	
    }

Similar Threads

  1. Swing application getting odd errors
    By Zeezj in forum New To Java
    Replies: 4
    Last Post: 09-14-2011, 07:14 PM
  2. Replies: 3
    Last Post: 08-29-2011, 01:54 AM
  3. Confusion with Payroll Application
    By Wolfie in forum New To Java
    Replies: 5
    Last Post: 04-23-2011, 07:00 PM
  4. Payroll part 3 errors help
    By arrech326 in forum New To Java
    Replies: 4
    Last Post: 03-08-2011, 05:43 AM
  5. Replies: 4
    Last Post: 01-04-2011, 12:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •