-1

Newb Java programmer here, Why isn't this calculator calculating?

The program should input Income from the user, and then Output their Federal Tax based on the calculations.

Federal Tax Rules: 15% on the first $45,282 of taxable income, + 20.5% on the next $45,281 of taxable income (on the portion of taxable income over $45,282 up to $90,563), + 26% on the next $49,825 of taxable income (on the portion of taxable income over $90,563 up to $140,388), +

Input:
Enter mark: 85
Output:
Grade is: A
Input:
Enter mark: 110
Output:
Enter a value between 0 and 100
Input:
Enter mark: 79.5
Output:
Grade is: B+
Input:
Enter mark: -10
Output:
Enter a value between 0 and 100 29% on the next $59,612 of taxable income (on the portion of taxable income over $140,388 up to $200,000), + 33% of taxable income over $200,000.

package practiceproblab4;

import java.util.Scanner;
/**
 *
 * @author JAVA NEWB
 */
public class PracticeProbLab4 {

/**
 * @param args the command line arguments
 */
public static void main(String[] args)
{

Scanner sc = new Scanner(System.in);
System.out.println("Enter your Income: ");
String In = sc.nextLine();
Double Income = Double.parseDouble(In);

calculateAndPrintTax(Income);
System.out.println("Your taxes are: " + TotalTax);
}

static double calculateAndPrintTax(double Income, double Tax)
{
    double tax;
    double difftax1;
    double difftax2;
    double difftax3;
    double difftax4;
    double TotalTax;

    if ((Income >= 45282) && (Income <= 200000))
    {
        if(Income<=45282)
        {
            tax = 45282 * 0.15;
            TotalTax = tax;
        }
        else if (Income > 45282 && Income <= 90653)
        {
            tax = 45282 * 0.15;
            difftax1 = (Income - 45282)* .205;
            TotalTax = tax + difftax1;
        }
        else if ((Income >90563) && (Income <= 140388))
        {
            tax = 45282 * 0.15;
            difftax1 = (Income - 45282) * .205;
            difftax2 = (Income - 90563) * 0.26;
            TotalTax = tax + difftax1 + difftax2;
        }
        else if ((Income > 140388) && (<= 200000))
        {
            tax = 45282 * 0.15;
            difftax1 = (Income - 45282) * .205;
            difftax2 = (Income - 90563) * 0.26;
            difftax3 = (Income - 140388) * 0.29;
            TotalTax = tax + difftax1 + difftax2 + difftax3;
        }
        else if ((Income > 200000))
        {
            tax = 45282 * 0.15;
            difftax1 = (Income - 45282) * .205;
            difftax2 = (Income - 90563) * 0.26;
            difftax3 = (Income - 140388) * 0.29;
            difftax4 = (Income - 200000) * 0.33;
            TotalTax = tax + difftax1 + difftax2 + difftax3 + difftax4;
        }
    else ((Income > 200000))
            {    
            tax = 45282 * 0.15;
            difftax1 = (Income - 45282) * .205;
            difftax2 = (Income - 90563) * 0.26;
            difftax3 = (Income - 140388) * 0.29;
            difftax4 = (Income - 200000) * 0.33;
            TotalTax = tax + difftax1 + difftax2 + difftax3 + difftax4;
            return TotalTax;
            }
    }
}
}
Jude
  • 545
  • 3
  • 20
R.Bar
  • 19
  • 1
  • 2
  • 9

1 Answers1

1

First of all you are printing nothing here (because you didn't initialize TotalTax anywhere in your main method):

calculateAndPrintTax(Income);
System.out.println("Your taxes are: " + TotalTax);

What you have to do is declare it in main and accept the return value of your method:

double TotalTax;

TotalTax = calculateAndPrintTax(Income);
System.out.println("Your taxes are: " + TotalTax);

Also, you have to remove the return in the else part of calculateAndPrintTax you have to put it outside the if/elseif/else clause:

if{
 // code here
}
else if{
 // code here
}
else{
 // code here
}
return TotalTax;
Jude
  • 545
  • 3
  • 20
  • To add on to this , you need to change calculateAndPrintTax(double Income, double Tax) to calculateAndPrintTax(double Income). – rootExplorr Feb 26 '16 at 01:48
  • When the changes that you suggested are made, I get two errors still – R.Bar Feb 26 '16 at 03:41
  • TotalTax = calculateAndPrintTax(Income); is underlined in red and else ((Income > 200000)) is also underlined in red – R.Bar Feb 26 '16 at 03:42