# Method Mixup

• November 6th, 2010, 03:57 PM
JavaCow
Method Mixup
Alright so I have to write this code this way as a method with a question input for my homework.
The assignment is make a print tax table method that will print a tax table from 50000 to 60000 tax income range at \$50 a row.

The only thing that I cant figure is the computation part where I println and the math is not computing properly. Also the compiler did not like my attempt to increment by 50.

How do I increment by 50 in the while loop?
What is wrong with my println statement?
Why cant I use the identifiers in the println statement?

Code :

```import java.util.Scanner;   public class ComputeTax { public static void main(String[] args) { //Create a Scanner Scanner input = new Scanner(System.in);   //Prompt the user to enter filing status System.out.print( "Would You like to print a Tax table of 50000 to 60000 1-Yes, 2-N"); int status = input.nextInt();   double taxableIncome=0;   if (status == 1) { printTable(status, taxableIncome); } else { System.out.println("Come back when you want to print in the 50k to 60k range!"); System.exit(0); }     public static double printTable(int status, double taxableIncome) { double taxableIncome = 50000; double endingJob = 60000;   System.out.println("Taxable\tSingle\tMarried\tMarried\tHead of"); System.out.println("Income\tFiler\tJoint\tSeparate\ta House");   while (taxableIncome <= endingJob) { System.out.println(taxableIncome + "\t" + (6000 * 0.10 + (27950 - 6000) * 0.15 + (taxableIncome - 27950) * 0.27)) + "\t" + (12000 * 0.10 + (46700 - 12000) * 0.15 + (taxableIncome - 46700) * 0.27) + "\t" + (6000 * 0.10 + (23350 - 6000) * 0.15 + (taxableIncome - 23350) * 0.27) + "\t" + (10000 * 0.10 + (37450 - 6000) * 0.15 + (taxableIncome - 37450) * 0.27) + "\n"; taxableIncome + 50; } } }```
• November 6th, 2010, 04:27 PM
javapenguin
Re: Method Mixup
Hmmmm....taxable income will be 0 when you call that method printTable.

You forgot a bracket to end your main method.

Code java:

```public static double printTable(int status, double taxableIncome) { double taxableIncome = 50000; double endingJob = 60000;   System.out.println("Taxable\tSingle\tMarried\tMarried\tHead of"); System.out.println("Income\tFiler\tJoint\tSeparate\ta House");   while (taxableIncome <= endingJob) { System.out.println(taxableIncome + "\t" + (6000 * 0.10 + (27950 - 6000) * 0.15 + (taxableIncome - 27950) * 0.27)) + "\t" + (12000 * 0.10 + (46700 - 12000) * 0.15 + (taxableIncome - 46700) * 0.27) + "\t" + (6000 * 0.10 + (23350 - 6000) * 0.15 + (taxableIncome - 23350) * 0.27) + "\t" + (10000 * 0.10 + (37450 - 6000) * 0.15 + (taxableIncome - 37450) * 0.27) + "\n"; taxableIncome + 50; } }```

This never returns anything, but it should return a double.

It's also usually best not to have a local variable with the same name and type as a parameter variable.

taxableIncome = taxableIncome + 50; will increase it by 50 for each iteration of the while loop.
• November 6th, 2010, 04:33 PM
javapenguin
Re: Method Mixup
You should have your find a way to later set your taxable income to in your method to return it, otherwise taxable income will be 0.

Also, you don't have an ending ) on your println statement in your method.

While status will be defined when you call the method, it appears that it need not be passed at all.

If the status isn't 1, it never even calls the method.

You should have it be

public static void printTable

Void means you're not returning anything.
• November 6th, 2010, 04:39 PM
javapenguin
Re: Method Mixup
Code java:

```public class ComputeTax { public static void main(String[] args) { //Create a Scanner Scanner input = new Scanner(System.in);   //Prompt the user to enter filing status System.out.print( "Would You like to print a Tax table of 50000 to 60000 1-Yes, 2-N"); int status = input.nextInt();   // double taxableIncome=0;   if (status == 1) { printTable(); } else { System.out.println("Come back when you want to print in the 50k to 60k range!"); System.exit(0); } }     public static void printTable() { double taxableIncome = 50000; double endingJob = 60000;   System.out.println("Taxable\tSingle\tMarried\tMarried\tHead of"); System.out.println("Income\tFiler\tJoint\tSeparate\ta House");   while (taxableIncome <= endingJob) { System.out.println(taxableIncome + "\t" + (6000 * 0.10 + (27950 - 6000) * 0.15 + (taxableIncome - 27950) * 0.27)) + "\t" + (12000 * 0.10 + (46700 - 12000) * 0.15 + (taxableIncome - 46700) * 0.27) + "\t" + (6000 * 0.10 + (23350 - 6000) * 0.15 + (taxableIncome - 23350) * 0.27) + "\t" + (10000 * 0.10 + (37450 - 6000) * 0.15 + (taxableIncome - 37450) * 0.27) + "\n"); taxableIncome = taxableIncome + 50; } } }```
• November 6th, 2010, 07:31 PM
JavaCow
Re: Method Mixup
The incrementing solution seemed obvious after i looked at it to increment a = a + 50;
I guess it became closed properly like I was instructed to do. Now it comes back with class errors.

/tmp/jc_29720/ComputeTax.java:24: class, interface, or enum expected
public static void printTable(int status, double taxableIncome) {
^
/tmp/jc_29720/ComputeTax.java:26: class, interface, or enum expected
double endingJob = 60000.0;
^
/tmp/jc_29720/ComputeTax.java:28: class, interface, or enum expected
^
/tmp/jc_29720/ComputeTax.java:29: class, interface, or enum expected
System.out.println("Income\tFiler\tJoint\tSeparate \ta House");
^
/tmp/jc_29720/ComputeTax.java:31: class, interface, or enum expected
while (taxableIncome <= endingJob) {
^
/tmp/jc_29720/ComputeTax.java:33: class, interface, or enum expected
double taxableIncome = taxableIncome + 50;
^
/tmp/jc_29720/ComputeTax.java:34: class, interface, or enum expected
}
^

Code :

``` public class ComputeTax { public static void main(String[] args) { //Create a Scanner Scanner input = new Scanner(System.in);   //Prompt the user to enter filing status System.out.print( "Would You like to print a Tax table of 50000 to 60000 1-Yes, 2-N"); int status = input.nextInt();   // double taxableIncome=0;   if (status == 1) { printTable(); } else { System.out.println("Come back when you want to print in the 50k to 60k range!"); System.exit(0); } } }     public static void printTable(int status, double taxableIncome) { double taxableIncome = 50000; double endingJob = 60000;   System.out.println("Taxable\tSingle\tMarried\tMarried\tHead of"); System.out.println("Income\tFiler\tJoint\tSeparate\ta House");   while (taxableIncome <= endingJob) { System.out.println(taxableIncome + "\t" + (6000 * 0.10 + (27950 - 6000) * 0.15 + (taxableIncome - 27950) * 0.27)) + "\t" + (12000 * 0.10 + (46700 - 12000) * 0.15 + (taxableIncome - 46700) * 0.27) + "\t" + (6000 * 0.10 + (23350 - 6000) * 0.15 + (taxableIncome - 23350) * 0.27) + "\t" + (10000 * 0.10 + (37450 - 6000) * 0.15 + (taxableIncome - 37450) * 0.27) + "\n"); taxableIncome = taxableIncome + 50; } } }```
• November 6th, 2010, 07:58 PM
javapenguin
Re: Method Mixup
You have one too many brackets at the end of the main method. Delete one of them.

You've inadvertantly told it to end the class there with that 3rd bracket.
• November 6th, 2010, 08:06 PM
javapenguin
Re: Method Mixup
Also

double taxableIncome = 50000;

How's it supposed to know if you're referring to this variable or the parameter of that method with the same name?

Only pass it a parameter if you want

printTables(1, 50000);

and you'll need to get rid of:

double taxableIncome = 50000;

then.

Also, as you can only call the method if status is 1, passing it as a parameter serves no purpose.

Ahhhh, I see now, you've cleared it to no parameters when you called it.

But it won't like it unless you clear the parameters from the method heading as well.
• November 7th, 2010, 05:50 PM
JavaCow
Re: Method Mixup
Code :

```import java.util.Scanner;   public class ComputeTax2 { public static void main(String[] args) { //Create a Scanner Scanner input = new Scanner(System.in);   //Prompt the user to enter filing status System.out.print( "Would You like to print a Tax table of 50000 to 60000 1-Yes, 2-N: "); int status = input.nextInt();   // double taxableIncome=0;   if (status == 1) { printTable(); } else { System.out.println("Come back when you want to print in the 50k to 60k range!"); System.exit(0); } }   public static void printTable() { double taxableIncome = 50000; double endingJob = 60000; System.out.println("Taxable\tSingle\tMarried\tMarried\tHead of"); System.out.println("Income\tFiler\tJoint\tSeparate\ta House");   while (taxableIncome <= endingJob) { System.out.println(taxableIncome + "\t" + (6000 * 0.10 + (27950 - 6000) * 0.15 + (taxableIncome - 27950) * 0.27) + "\t" + (12000 * 0.10 + (46700 - 12000) * 0.15 + (taxableIncome - 46700) * 0.27) + "\t" + (6000 * 0.10 + (23350 - 6000) * 0.15 + (taxableIncome - 23350) * 0.27) + "\t" + (10000 * 0.10 + (37450 - 6000) * 0.15 + (taxableIncome - 37450) * 0.27) + "\n"); taxableIncome = taxableIncome + 50; } } }```

I cant really tell if this table actually prints the header is there a way to verify that the first 2 println statements occur?