# Help I'm stuck on code.

• January 27th, 2010, 08:53 PM
GreenM
Help I'm stuck on code.
I'm trying to get the following assignment completed but I seem to be stuck.. If I can get help I would appreciate it. This is whats required of the of the program.

I am to write a program that will calculate a person's income tax based upon the following table.
Income -------------------------- Percent Withheld
0 - \$10,000 ------------------- 0%
\$10,000.01 - \$25,000 --------------------- 10%
\$25,000.01 - \$50,000 -------------------- 20%
> \$50,000.01 -------------------- 35%

Than my program should read in the annual salary, calculate the monthly pay, and then remove the income tax. After that print out the yearly salary, gross monthly pay, net monthly pay, and the amount of the monthly withholding.

I have done the input prompts for the annual salary and monthly pay. I seem to be stuck on removing the income tax and how I would go about the printout output for the net pay and monthly withholding.
Here is what I have so far.. I presume I will need to use an if else statement but not sure how to set it up.. any help I'll be sure to return it?
Code :

```import java.text.DecimalFormat; public class IncomeTaxCalc { public static void main(String[] args) { double salary; double pay; double netPay; salary = GetData.getDouble("Enter yearly salary"); pay = salary / 12.0; netPay = DecimalFormat myNumber = new DecimalFormat("\$#,##0.00"); System.out.println("Yearly salary: " + salary + "\n"+"Gross Monthly Pay:" + pay + "\n"+"New Monthly Pay:" + "\n"+"Witholding:" + ); }//end main }//end class```
• January 28th, 2010, 03:08 AM
GreenM
Re: Help I'm stuck on code.
• January 28th, 2010, 03:42 AM
helloworld922
Re: Help I'm stuck on code.
Patience :P

A simple way to implement this logically is by comparing the income with the maximum values of each range using if-else statements (can you see why?)

Also, it's important to figure out if \$10000 belongs to the lower bracket or the higher bracket (also with the other brackets). This will determine if you need a < or a <= operator.

Code :

```double taxRate = 0; if (pay< 10000) { taxRate = 0; } else if (pay < 25000) { taxRate = 0.1; } else if (pay < 50000) { taxRate = .2; } else { // pay > 50000 taxRate = .3; }```
• January 29th, 2010, 08:27 PM
GreenM
Re: Help I'm stuck on code.
Quote:

Originally Posted by helloworld922
Patience :P

```double taxRate = 0; if (pay< 10000) { taxRate = 0; } else if (pay < 25000) { taxRate = 0.1; } else if (pay < 50000) { taxRate = .2; } else { // pay > 50000 taxRate = .3; }```