jeudi 25 février 2016

Java - Simple Tax Calculator using If and if else statements(2)

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), +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. Sample Input / Output: Income: Enter Income: 50000 Output: Federal Tax: 7759.49 Income: Enter Income: 230000 Output: Federal Tax: 56217

The Problem with My Code:

  • TotalTax = calculateAndPrintTax(Income); *is underlined in red
  • else ((Income > 200000)) is underlined in red AND gives the expectation: " ';' is expected"

Here's the code.... 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);

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

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

    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) && (Income<= 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