jeudi 25 février 2016

Java - Simple Tax Calculator using If and if else statements

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;
            }
    }
}

}

Aucun commentaire:

Enregistrer un commentaire