0

I am having trouble getting the health deductions from the TaxablePay method to the getNetPay method.
I have tried everything I can think of including using a taxablePay class. I am running out of ideas. I have below...

1.The program description(what i want the program to do).
2.The expected output of the program.
3.The output I receive when I compile my program.
4.The code I have so far(with comments to the problem areas)

DESCRIPTION
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Create a program that will calculate employee’s weekly pay as follows:
Inputs:
1.Name
2.Hours worked
3.Rate of Pay ($ / hour)
4.Marital Status (Married, Single)
5.# of Dependents
6.Healthcare (Yes or No)
7.Keeps asking for additional inputs and creating the outputs until a name of X is given.
Outputs:
1.Gross pay (Hours over 40 are paid at time and ½)
2.Taxable Pay (Gross – Medical Deduction, if selected, from table below)
3.Federal Tax
4.Net Pay (Gross Pay – Health Care Deduction (if any) – Federal Tax).
5.If any of the inputs are unreasonable, tell user with a message and force reentry of the data.

Additional Requirements:
1.Use functions for major tasks
a.Calculate Gross Pay
b.Calculate Health Deductions
c.Calculate Tax
d.Calculate Net Pay
2.Other than constants, do NOT use global variables
(e.g You need to pass variable between functions through the argument list).

Tax Calculation Pseudocode

If married
    TaxablePay = GrossPay – 150 – 70.0 * NumberDependents
    if healthcare
        TaxablePay = TaxablePay – 100
    if TaxablePay > 800
        Tax = (TaxablePay - 800) * .35 + (800 - 500) * .25 + (500 - 200) * .15 +200 * .10
    else if TaxablePay > 500
        Tax = (TaxablePay - 500) * .25 + (500 – 200) * .15 +200 * .10
    else if TaxablePay > 200
        Tax = (TaxablePay - 200) * .15 +200 * .10
    else
        Tax = TaxablePay * .10
else
    TaxablePay = GrossPay – 75 – 70.0 * NumberDependents
    if healthcare
        TaxablePay = TaxablePay – 60
    if TaxablePay > 400
        Tax = (TaxablePay - 400) * .35 + (400 - 250) * .25 + (250 - 100) * .15 +100 * .10
    else if TaxablePay > 250
        Tax = (TaxablePay - 250) * .25 + (250 – 100) * .15 +100 * .10
    else if TaxablePay > 100
        Tax = (TaxablePay - 100) * .15 +100 * .10
    else
        Tax = TaxablePay * .10

CODE OUTPUT
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
WHAT IT SHOULD BE:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A married employee with 45 hours at $20.00/hour, 2 dependents and taking health care:
Employee name: Victoria Swanson
Gross pay is 950.0
Taxable pay is 560.0
Tax is 80.0
Your net pay is 770.0
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
WHAT I GET
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A married employee with 45 hours at $20.00/hour, 2 dependents and taking health care:
Employee name: Victoria Swanson
Gross pay is 950.0
Taxable pay is 870.0 //wrong
Tax is 80.0
Your net pay is 790.0 //wrong

public static void main(String[] args) {
              String name;               // hold name input 
              double grossPay;           // To hold gross pay  
              double taxablePay;         // To hold taxable pay  
              double federalTax;         // To hold federal tax  
              double net;    

              Scanner keyboard = new Scanner(System.in); 
              System.out.print("What is your name? ");  
              name = keyboard.nextLine();  

              // get the gross pay.  
              grossPay = getGross();  

              // get the taxable pay.  
              taxablePay = getTaxablePay(grossPay);  

              // get the federal tax.  
              federalTax = getFedTax(grossPay, taxablePay);  

              // get the net pay.  
              net = getNetPay(taxablePay, federalTax);  

              // display results  
              displayResults(grossPay, federalTax, taxablePay, net, name);  

              // stop program  

          }  

           public static double getGross()  
           {  

              double hours;              // hold hours worked  
              double payRate;            // hold pay rate  
              double overTime;           // hold overtime  
             double overTimeHours;      // hold overtime hours  
              Scanner keyboard = new Scanner(System.in);  

              System.out.print("How many hours did you work this week? ");  
              hours = keyboard.nextDouble();  
              System.out.print("What is your pay rate? ");  
              payRate = keyboard.nextDouble();  

              if (hours > 40)  
              {  
                 overTimeHours = (hours - 40);          
                 overTime = overTimeHours * payRate * 1.5;  
                 return (hours - overTimeHours) * payRate + overTime;  
              }    
              else 
              {  
                 return (hours * payRate);  
              }  

           }  





      public static double getTaxablePay(double grossPay)  
       {  
          double taxPay;  //I need to get the answers from the user to the netPay while still calculating Tax.
          int dependents;  
          String maritalStatus;  
          double Tax;  
          String healthcare; 




          Scanner keyboard = new Scanner(System.in);  
          System.out.print("What is you marital status?(married = M, single = S) ");  
          maritalStatus = keyboard.nextLine();  
          System.out.print("Do you have healthcare?(yes = Y, no = N) ");  
          healthcare = keyboard.nextLine(); 
          System.out.print("How many dependents do you have? ");  
          dependents = keyboard.nextInt();   


          if (maritalStatus.equals("M"))  
          {  
                taxPay = grossPay - 150 - 70.0 * dependents;
                System.out.println(healthcare);
             if (healthcare.equals("Y"))  
             {  
                taxPay = taxPay - 100;  
                marriedHealthcareDeductions();

             }  
             System.out.println(taxPay);
           if (taxPay > 800)  
             {  
                Tax = (taxPay - 800) * .35 + (800 - 500) * .25 + (500 - 200) * .15 +200 * .10;  

                return Tax;
             }  
             else if (taxPay > 500)  
             {  
                Tax = (taxPay - 500) * .25 + (500 - 200) * .15 +200 * .10;
                System.out.println(Tax); 
                return Tax;  
             }    
             else if (taxPay > 200)  
             {  
                Tax = (taxPay - 200) * .15 +200 * .10;
                return Tax;  
             }  
             else 
             {  
                Tax = taxPay * .10;  

                return Tax;   
             }  
         }  
          else 
          {  
             taxPay = grossPay - 75 - 70.0 * dependents;  

             if (healthcare.equals("Y"))  
             {  
               taxPay = taxPay - 60;
               singleHealthcareDeductions();
             }  
             if (taxPay > 400)  
             {  
                Tax = (taxPay - 400) * .35 + (400 - 250) * .25 + (250 - 100) * .15 +100 * .10; 

             }  
             else if (taxPay > 250)  
             {  
                Tax = (taxPay - 250) * .25 + (250 - 100) * .15 +100 * .10;  
             }  
             else if (taxPay > 100)  
             {  
                Tax = (taxPay - 100) * .15 +100 * .10;  
             }  
             else 
             {  
                Tax = taxPay * .10;  
             }  
          }  
          return Tax;  

       }    


       public static double getFedTax(double grossPay, double taxablePay)  //This is definitely not right
       {  
          return (grossPay - taxablePay);  
       }    

       public static double getNetPay(double taxablePay, double federalTax)  //This is definitely not right
       {  
          return (federalTax - taxablePay); 
       }                                   

       public static void displayResults(double grossPay, double federalTax, double taxablePay, double net, String name)  
       {  
          System.out.println("Employee name: " + name); 
          System.out.println("Gross pay is " + grossPay);  
          System.out.println("Taxable pay is " + federalTax); //This is wrong 
          System.out.println("Tax is " + taxablePay);  
          System.out.println("Your net pay is " + net);  //This is wrong
       }  

Any advice is appreciated. I am in a pitfall with this program and would love some expert advice. Thanks in advance!!!!

2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by JamesCherrill
1

If you need variables to be shared between different methods, then declare them in the class but outside any one method. Variables declared at the class level can be used in any method

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.