# Tax calculation program help!!

• 11-28-2011, 05:49 PM
sabarooni
Tax calculation program help!!
Hi, I am trying to create a program which calculates tax for x amount of years, given annual salary (S), annual increase (I), and number of years (X).

the number of years must be between 1 and 10, and is input by the user. The program then displays the gross tax and net tax and salary for the year for x number of years.

Could anyone please help me out on what I should use in the program for the number of years? I was thinking about using a for loop, but I'm not sure how I would implement it.

• 11-28-2011, 06:25 PM
KevinWorkman
Re: Tax calculation program help!!
What do you mean by "what I should use in the program for the number of years"? Sounds like an int to me.
• 11-28-2011, 06:32 PM
sabarooni
Re: Tax calculation program help!!
Quote:

Originally Posted by KevinWorkman
What do you mean by "what I should use in the program for the number of years"? Sounds like an int to me.

ye I am using an int, and yea I don't think I explained it very well lol

say, for example the number of years input is 3, basic salary is £15,000, annual increase is 10%

then the output needs to be (for gross salary):

year1: 15, 000
year2: 16,500
year3: 18,150

I can do all the calculations etc, but I don't know how to make it display the desired number of years. I also need to display the tax for each year, but I think it will be the same method as displaying the gross salary.

Any tips you can give?
• 11-28-2011, 07:30 PM
KevinWorkman
Re: Tax calculation program help!!
Well, a for loop sounds reasonable to me. What happened when you tried that?
• 11-28-2011, 08:06 PM
sabarooni
Re: Tax calculation program help!!
Quote:

Originally Posted by KevinWorkman
Well, a for loop sounds reasonable to me. What happened when you tried that?

I haven't yet tried to put the for loop in because I don't fully understand how it works but I will try it now and reply with results, thanks for the tip!
• 11-28-2011, 08:13 PM
KevinWorkman
Re: Tax calculation program help!!
• 11-28-2011, 08:49 PM
sabarooni
Re: Tax calculation program help!!
Quote:

Originally Posted by KevinWorkman

Thanks alot!

I used a for statement, and now if I input the year and basic salary, it prints out the gross tax for each of the years.
Now I just need to be able to increment the annual percentage increase each year, hopefully shouldn't be too hard!
• 11-28-2011, 09:34 PM
sabarooni
Re: Tax calculation program help!!
Hi I can't seem to implement the annual increase, I can only get as far as the program printing out the same starting salary for each year, can anyone help?
• 11-28-2011, 09:36 PM
KevinWorkman
Re: Tax calculation program help!!
Quote:

Originally Posted by sabarooni
Hi I can't seem to implement the annual increase, I can only get as far as the program printing out the same starting salary for each year, can anyone help?

If you want help, you should provide an SSCCE that demonstrates what you have so far. Otherwise we're just guessing.
• 11-28-2011, 09:46 PM
sabarooni
Re: Tax calculation program help!!
Code:

``` import java.util.Scanner ; class Salary {         static Scanner input = new Scanner (System.in) ;                 public static void main (String args [])         {         //////////////////////////////////////////////////////////// //DECLERATIONS ////////////////////////////////////////////////////////////                 double basicsalary, annualincrease ;                 int years ;                 //////////////////////////////////////////////////////////// //INPUT ////////////////////////////////////////////////////////////                                 System.out.print("Enter annual salary before tax: ") ;                 basicsalary = input.nextDouble () ;                 System.out.print("Enter annual percentage increase in salary: ") ;                 annualincrease = input.nextDouble () ;                 System.out.print("Enter number of years to be calculated: ") ;                 years = input.nextInt () ;                 //////////////////////////////////////////////////////////// //INSTANTIATE A COPY OF SALARYMATHS ////////////////////////////////////////////////////////////                 Salarymaths sm = new Salarymaths () ;                 //////////////////////////////////////////////////////////// //ANNUAL GROSS SALARY OUTPUT ////////////////////////////////////////////////////////////                 System.out.println () ;                 System.out.println ("Gross Salary before tax for "+years+" years: ") ;                                 for (int g=1 ; g<=years ; g++)                 {                         System.out.print ("Year "+g+": ") ;                         System.out.println (basicsalary) ;                 }                                 } }```
This is pretty much what I have so far, an example would be:

basicsalary: 15,000
annualincrease: 20
years: 5

This prints out:

Year1 15000
Year2 15000
Year3 15000
Year4 15000
Year5 15000

I want the salary to increase by the inputted percentage (in this case, 20) each year, and I have no idea how to do it, I am guessing I should use a sequence somehow but I have no idea where to start!
• 11-28-2011, 10:06 PM
sabarooni
Re: Tax calculation program help!!
Quote:

Originally Posted by KevinWorkman
If you want help, you should provide an SSCCE that demonstrates what you have so far. Otherwise we're just guessing.

is that what you meant by SSCCE? :)
• 11-28-2011, 11:00 PM
sabarooni
Re: Tax calculation program help!!
I figured it out! thanks for the help Kevin!