Home

Thursday, October 15, 2015

/* Alias: Ydahal1
 Name: Yadhap Dahal
 CRN: 58053
 File Name: taxCalculator.java
 Description: this program  calculates the tax based on yearly earning and martial status and dependency */

import java.util.Scanner;

public class taxCalculator{
    public static void main(String [] args){
        
        //Import scanner
        Scanner input = new Scanner(System.in);
        
        // display code for filing status and prompt user to enter their status
        System.out.print( "Enter 0, if you are filing Single " + "\nEnter 1, if you are married or qualifying widower" +
                         "\nEnter 2, if you are married but saperated " + "\nEnter 3, if you are filing as a head of household"
                         + "\n \nStatus:" );
        int status = input.nextInt();
        
        //Prompt user to enter annual taxable income
        System.out.print("Enter your annual income: ");
        double income = input.nextDouble();
        
        //variable
        double tax = 0;
        
        
        //If user status is 0
        if  (status == 0) {
            
            if (income <= 8350)
                tax = income * 0.10;
            
            else if (income <= 33950)
                tax = (8350 * 0.10 + (income - 8350) * 0.15);
            
            
            else if (income <= 82250)
                tax = ((8350 * 0.10) + ((income - 8350) * 0.15) + ((income - 33950) * 0.25));
            
            else if (income <= 171550)
                tax = 8350 * 0.10 + (income - 8351) * 0.15 + (income - 33950) * 0.25 +
                (income - 82250) * 0.28;
            
            else if (income <= 372950)
                tax = 8350 * 0.10 + (income - 8351) * 0.15 + (income - 33950) * 0.25 + (income - 82250) * 0.28 + (income - 171550) * 0.33;
            
            else
                tax = 8350 * 0.10 + (income - 8351) * 0.15 + (income - 33950) * 0.25 + (income - 82250) * 0.28 + (income - 171550) + (income - 372950)* 0.35 + (income - 372950) * 0.35;
        }
        
        
        //If user status is 1
        else if (status == 1){
            
            
            if (income <= 16700)
                tax = income * 0.10;
            
            
            else if (income <= 67900)
                tax = (16700 * 0.10) + (income - 16700)* 0.15;
            
            else if (income <= 137050)
                tax = (16700 * 0.10) + (income - 16700)* 0.15 + (income - 67900) * 0.25;
            
            
            else if (income <= 208850)
                tax = (16700 * 0.10) + (income - 16700)* 0.15 + (income - 67900) * 0.25 +
                (income - 137050) * 0.28;
            
            
            else if (income <= 372950)
                tax = (16700 * 0.10) + (income - 16700)* 0.15 + (income - 67900) * 0.25 + (income - 137050) * 0.28 + (income - 208850) * 0.33;
            
            
            else if (income < 372950)
                tax = (16700 * 0.10) + (income - 16700)* 0.15 + (income - 67900) * 0.25 + (income - 137050) * 0.28 + (income - 208850) * 0.33 + (income - 372959) * 0.35;
        }
        
        // If status is 2
        else if (status == 2){
            if ( income <= 8350)
                tax = income * 0.10;
            
            else if ( income <= 33950)
                tax = (8350 * .10) + (income - 8350) * 0.15;
            
            else if ( income <= 68525)
                tax = (8350 * .10) + (income - 8350) * 0.15 + (income - 33950) * 0.25;
            
            else if ( income <= 104425)
                tax = (8350 * .10) + (income - 8350) * 0.15 + (income - 33950) * 0.25 + (income - 68525) * 0.28;
            
            else if ( income <= 186475)
                tax = (8350 * .10) + (income - 8350) * 0.15 + (income - 33950) * 0.25 + (income - 68525) * 0.28 + (income - 104425) * 0.33;
            
            else
                tax = (8350 * .10) + (income - 8350) * 0.15 + (income - 33950) * 0.25 + (income - 68525) * 0.28 + (income - 104425) * 0.33 + (income - 186475) * 0.35;
            
        }
        
        // If status is 3
        else if (status == 3){
            
            if (income <= 11950)
                tax = income * 0.10;
            
            else if (income <= 45500)
                tax = (11950 * 0.10) + (income - 11950) * 0.15;
            
            else if (income <= 117450)
                tax = (11950 * 0.10) + (income - 11950) * 0.15 + (income - 45500) * 0.25;
            
            
            else if (income <= 190200)
                tax = (11950 * 0.10) + (income - 11950) * 0.15 + (income - 45500) * 0.25 + (income - 117450) * 0.28;
            
            else if (income <= 372950)
                tax = (11950 * 0.10) + (income - 11950) * 0.15 + (income - 45500) * 0.25 + (income - 117450) * 0.28 + (income - 190200) * 0.33;
            
            else 
                tax = (11950 * 0.10) + (income - 11950) * 0.15 + (income - 45500) * 0.25 + (income - 117450) * 0.28 + (income - 190200) * 0.33 + (income - 372950) * 0.35;
        }
        
        // if user enters invalid status
        else 
            System.out.print( "Invalid Status, Note :- Status should be either 0, 1, 2 or 3");
        
        // Results
        System.out.print( "Your Total Tax is: " + (int) (tax *100)/100.0 + 
                         "\nYour income after tax is " + (int)((income - tax)*1000)/100.00) ;
    }
    
}

No comments:

Post a Comment