Skip to content

Instantly share code, notes, and snippets.

@joeyv
Created October 24, 2013 12:50
Show Gist options
  • Select an option

  • Save joeyv/7136641 to your computer and use it in GitHub Desktop.

Select an option

Save joeyv/7136641 to your computer and use it in GitHub Desktop.
Calculates your tax cost
import java.util.Scanner;
import java.text.*;
public class Tax {
public static void main(String[] args)
{
// Declare variables
int allowedDeduction = 10000, deduction = 2000;
int grossIncome, dependents;
double taxRate = 0.2;
double finalIncome;
// Scan in input for income and dependents
Scanner scan = new Scanner(System.in);
grossIncome = scan.nextInt();
dependents = scan.nextInt();
// Calculate tax
dependents = dependents * deduction; // every dependant is worth 2k
finalIncome = ((grossIncome - dependents) - allowedDeduction) * taxRate; // minus dependents and the 10k allowed tax, then multiply by the 2% tax rate
// money format
NumberFormat nf = NumberFormat.getCurrencyInstance();
// print out
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