Last active
December 26, 2015 05:58
-
-
Save imryan/7104042 to your computer and use it in GitHub Desktop.
Calculates income tax with dependencies.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.text.*; | |
public class Tax { | |
public static void main(String[] args) | |
{ | |
// Declare variables | |
Scanner sc = new Scanner(System.in); | |
final double TAX_RATE = 0.2; | |
final int ALLOWED_DEDUCTION = 10000; | |
final int DEDUCTION = 2000; | |
int grossIncome, dependents; | |
double finalIncome; | |
// Get input for income and dependents | |
grossIncome = sc.nextInt(); | |
dependents = sc.nextInt(); | |
// Create number formatter currency instance | |
NumberFormat nf = NumberFormat.getCurrencyInstance(); | |
// Calculate tax | |
dependents *= DEDUCTION; | |
finalIncome = ((grossIncome - dependents) - ALLOWED_DEDUCTION) * TAX_RATE; | |
// Output tax | |
System.out.println("\nIncome: " + nf.format(finalIncome)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment