• Post Reply Bookmark Topic Watch Topic
  • New Topic

not a statement error  RSS feed

 
Stella Brannon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm hoping I can get some help here as I just don't know how to fix this. I appreciate any help anyone can provide.

I'm writing a program to print a tax table. I am finished and trying to compile but I keep getting an error on one line of code.

I'm getting a 'not a statement error on this for loop.

for(TaxableIncome = 50000; TaxableIncome <= 60000; TaxableIncome+50)
{
System.out.println(TaxableIncome+"\t"+"\t"+ computeTax(0,TaxableIncome)+"\t"+"\t"+computeTax(1,TaxableIncome)+"\t"+
"\t"+computeTax(2,TaxableIncome)+"\t"+"\t"+ computeTax(3,TaxableIncome));
System.out.println();
}

Here is the complete program:
package computetaxtable;

//method to compute tax
public class ComputeTaxTable {

public static void main(String[] args){

//print headers for table
System.out.println("Taxable"+ "\t" + "\t" + "Single" +"\t" +"\t"+ "Married Joint"+ "\t"+ "\t" + "Married"+ "\t"+"\t"+ "Head of");
System.out.println( "Income"+"\t"+"\t"+"\t" + "\t" + "or Qualifying"+"\t"+"\t"+"Separate"+"\t"+"a House");
System.out.println("\t" + "\t" +"\t" + "\t" +"Widow(er)");
System.out.println("-----------------------------------------------------------------------");

double TaxableIncome;

for(TaxableIncome = 50000; TaxableIncome <= 60000; TaxableIncome+50)
{
System.out.println(TaxableIncome+"\t"+"\t"+ computeTax(0,TaxableIncome)+"\t"+"\t"+computeTax(1,TaxableIncome)+"\t"+
"\t"+computeTax(2,TaxableIncome)+"\t"+"\t"+ computeTax(3,TaxableIncome));
System.out.println();
}
}
public static double computeTax(int status, double TaxableIncome){

double result=0;

for(status = 0; status <=3; status++){

//Statements to compute tax for single
if (status == 0)
if (TaxableIncome <= 8350)
result = TaxableIncome * 0.10;
else if (TaxableIncome <= 33950)
result = 8350 * 0.10 + (TaxableIncome - 8350) * 0.15;
else if (TaxableIncome <= 82250)
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(TaxableIncome - 33950) * 0.25;
else if (TaxableIncome <= 171550)
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (TaxableIncome - 82250) * 0.28;
else if (TaxableIncome <= 372950)
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
(TaxableIncome - 171550) * 0.33;
else
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
(372950 - 171550) * 0.33 + (TaxableIncome - 372950) * 0.35;


//Statements to compute tax for Married Joint
else if(status == 1)
if (TaxableIncome <= 16700)
result = TaxableIncome * 0.10;
else if (TaxableIncome <= 67900)
result = 16700 * 0.10 + (TaxableIncome - 16700) * 0.15;
else if (TaxableIncome <= 137050)
result = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(TaxableIncome - 67900) * 0.25;
else if (TaxableIncome <= 208850)
result = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(137050 - 67900) * 0.25 + (TaxableIncome - 137050) * 0.28;
else if (TaxableIncome <= 372950)
result = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 +
(TaxableIncome - 208850) * 0.33;
else
result = 16700 * 0.10 + (67900 - 16700) * 0.15 +
(137050 - 67900) * 0.25 + (208850 - 137050) * 0.28 +
(372950 - 208850) * 0.33 + (TaxableIncome - 372950) * 0.35;


//Statements to compute tax for Married Separate and Qualifying Widower
else if (status == 2)
if (TaxableIncome <= 8350)
result = TaxableIncome * 0.10;
else if (TaxableIncome <= 33950)
result = 8350 * 0.10 + (TaxableIncome - 8350) * 0.15;
else if (TaxableIncome <= 68525)
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(TaxableIncome - 33950) * 0.25;
else if (TaxableIncome <= 104425)
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(68525 - 33950) * 0.25 + (TaxableIncome - 68525) * 0.28;
else if (TaxableIncome <= 186475)
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 +
(TaxableIncome - 104425) * 0.33;
else
result = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(68525 - 33950) * 0.25 + (104425 - 68525) * 0.28 +
(186475 - 104425) * 0.33 + (TaxableIncome - 186475) * 0.35;


//Statements to compute tax for Head of a House
else if (status == 3)
if (TaxableIncome <= 11950)
result = TaxableIncome * 0.10;
else if (TaxableIncome <= 45500)
result = 11950 * 0.10 + (TaxableIncome - 11950) * 0.15;
else if (TaxableIncome <= 117450)
result = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(TaxableIncome - 45500) * 0.25;
else if (TaxableIncome <= 190200)
result = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(117450 - 45500) * 0.25 + (TaxableIncome - 117450) * 0.28;
else if (TaxableIncome <= 372950)
result = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 +
(TaxableIncome - 190200) * 0.33;
else
result = 11950 * 0.10 + (45500 - 11950) * 0.15 +
(117450 - 45500) * 0.25 + (190200 - 117450) * 0.28 +
(372950 - 190200) * 0.33 + (TaxableIncome - 372950) * 0.35;

//Print tax for Head of a House
}
return result;}
}
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I bolded the part that's wrong:
for (TaxableIncome = 50000; TaxableIncome <= 60000; TaxableIncome+50)

Go back to your notes or look up Java for-loop syntax

A couple of things for your reference going forward:
1. When posting code, please UseCodeTags (←click on that link to learn how to do that)
2. Choose an appropriate forum to post your question. Please do not post your question to multiple forums

Welcome to the Ranch!
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, standard Java naming conventions dictate that variable names start with a lowercase letter. Your TaxableIncome variable should be taxableIncome instead.
 
Stella Brannon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much!
 
Stella Brannon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On this same code, I have corrected the variables and the for loop. However the status is not changing so the table is only calculating the single tax rate for each status. I changed the parameter in the method but it isn't being changed when it enters the for loop.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you posted properly formatted code surrounded by code tags, otherwise people will be disinclined to read through the code that you previously provided.
 
Stella Brannon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies. I thought I did. I edited the post.(just saw it didn't allow me to edit.)

Here it is now.
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stella,

Thank you for updating with code tags and (in case no one else did it) Welcome to the Ranch!

Let's take a look at the first few lines of the computeTax method:


What happens to the int value of status when the for loop starts? Do you see that it's being changed to 0? The for loop then runs four iterations (0, 1, 2, 3), and because of the brace usage at the bottom of the method, returns the result of the final iteration.

Two suggestions:
1) Methods should really do just one thing. computeTax should just figure out the computed tax and return that tax. Nothing more. The method that calls computeTax should be where the decision to decide which status and taxable income is required. You actually have that part done already in the main. So, just remove the loop and let computeTax do what it is designed to do.
2) You really need to use more braces. It quickly becomes very difficult to follow loop and conditional logic with the human eye if braces are skipped.
For example, see how much easier the logic is to follow when braces are used:



Cheers!
Chris
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and I feel I would be remiss if I didn't mention that these println statements:
System.out.println("Taxable"+ "\t" + "\t" + "Single" +"\t" +"\t"+ "Married Joint"+ "\t"+ "\t" + "Married"+ "\t"+"\t"+ "Head of");

Can be more easily written as:
System.out.println("Taxable\t\tSingle\t\tMarried Joint\t\tMarried\t\tHead of");

There are actually better ways you'll learn to do that as you get more familiar with Strings and Formatting, but I'll leave that for now.
I just mention this as all that SHIFT+" ... SHIFT+PLUS ... SHIFT+" can get tiring on your wrists.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

It is also easier to read without such long lines, which I have broken and you can see how to do it (they should probably be shorter still, though) and without the coloured text. Some people find certain colours difficult to read so use black text throughout as a default.
All those numbers are really difficult to understand. I presume they represent tax rates and thresholds. If a threshold changes, you will find updating it a nightmare.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!