# Thread: Problem with Taxes in Payroll Calc

1. Member
Join Date
Aug 2013
Posts
2
Rep Power
0

## Problem with Taxes in Payroll Calc

The problem I keep getting is when I try to enter the if loop to calculate the taxes (lines 68-87). I don't know if its because of the number of if loops I have consecutively or not, but the calculation of taxes are wrong when I add more than one if loop; When I use just use one it works fine. I can't figure it out, what am I not getting? Thanks for suggestions!

Java Code:
```import java.util.Scanner;

public class PayrollCalcd {

public static final double TAXES_LOW = .05;
public static final double TAXES_MID = .0785;
public static final double TAXES_HIGH = .08975;

{
return hours*rate;
}

{
return hours*rate;
}

{
return amount;
}

double addOvertime(double hours, double overtime, double rate)
{
return overtime = (hours-40)*(rate*1.5);
}

public static void main(String[] args)
{
PayrollCalcd prc = new PayrollCalcd();
Scanner myScanner = new Scanner(System.in);
double hours, rate, amount = 0;
double wSalary = 0;
double mSalary = 0;
double cSalary = 0;
double overtime = 0;
int wnum = 0;
int cnum = 0;
int mnum = 0;
double deduction = 0;

do{
System.out.println("'W' - enter worker");
System.out.println("'M' - enter a manager");
System.out.println("'C' - enter a contractor");
System.out.println("'D' - complete calculations and print results");

{
System.out.print("Please enter the worker's pay rate: ");
rate = myScanner.nextDouble();
System.out.print("Please enter the number of hours worked: ");
hours = myScanner.nextDouble();
wnum++;
if (hours > 40)
{
wSalary += (rate*40) + prc.addOvertime(hours, overtime, rate);
}

else{
}

if (wSalary <= 10000)
{
deduction = wSalary * TAXES_LOW;
wSalary -= deduction;

}

if (wSalary <= 20000)
{
deduction = wSalary * TAXES_MID;
wSalary -= deduction;

}

if (wSalary > 20000)
{
deduction = wSalary * TAXES_HIGH;
wSalary -= deduction;

}

}

{
System.out.print("Please enter the worker's pay rate: ");
rate = myScanner.nextDouble();
System.out.print("Please enter the number of hours worked: ");
hours = myScanner.nextDouble();
mnum++;
if (hours > 40)

mSalary += (rate*40) + prc.addOvertime(hours, overtime, rate);

else
}

{
System.out.print("Please enter the amount the worker is " +
"owed: ");
amount = myScanner.nextDouble();
cnum++;
}

{
System.out.println("RESULTS:");
System.out.print("Number of workers: ");
System.out.println(wnum);
System.out.print("Number of managers: ");
System.out.println(mnum);
System.out.print("Number of contractors: ");
System.out.println(cnum);
System.out.print("Total Gross Salaries: ");
System.out.println(wSalary + mSalary + cSalary);
System.out.print("Total Taxes Withheld: ");
System.out.println(deduction);
}

}

}```

2. ## Re: Problem with Taxes in Payroll Calc

If the salary is less than 10,000, you know it's less than 20,000. Looks like a job for an if/else statement.

By the way, there's no such thing as an if loop.

3. ## Re: Problem with Taxes in Payroll Calc

If wSalary <= 10000 then most certainly wSalary <= 20000; do you want to execute the body of both if-statements? ('if' is a statement, not a loop ).

kind regards,

Jos

edit: darn, who's the slowest old sod again?

4. Member
Join Date
Aug 2013
Posts
2
Rep Power
0

## Re: Problem with Taxes in Payroll Calc

Ah, I see. Thanks guys. Sorry for the waste of a post.

5. ## Re: Problem with Taxes in Payroll Calc

It's not a waste. You figured out the problem and learned something in the process, right? That's exactly what these forums are for!

#### Posting Permissions

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