Skip to content

Instantly share code, notes, and snippets.

@joeyv
Last active December 28, 2015 16:49
Show Gist options
  • Save joeyv/7531190 to your computer and use it in GitHub Desktop.
Save joeyv/7531190 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.text.*;
public class TaxCalculator{
public static void main(String[]args){
int play, income;
double tax;
//Creating Scanner, Random Generator,& formating currency
Scanner scan = new Scanner(System.in);
Random generator = new Random();
NumberFormat nf = NumberFormat.getCurrencyInstance();
//Start Screen
System.out.println ("[1] Play \n[2] Quit");
play = scan.nextInt();
//When Playing
while (play == 1){
//Create & Display Random Number
income = generator.nextInt(150000) + 1;
System.out.println ("Your income is: " + nf.format(income));
//Calculate
if (income <= 5000){
tax = 0;
income *= tax;
System.out.print ("You would pay " + nf.format(income) + " in taxes with a tax rate of 0%");
} else if (income <= 15000 && income > 5000){
tax = 0.05;
income *= tax;
System.out.println ("You would pay " + nf.format(income) + " in taxes with a tax rate of 5% !");
} else if (income <= 100000 && income > 15000){
tax = 0.3;
income *= tax;
System.out.println ("You would pay " + nf.format(income) + " in taxes with a tax rate of 30% !");
} else if (income > 100000){
tax = 0.4;
income *= tax;
System.out.println ("You would pay " + nf.format(income) + " in taxes! with a tax rate of 40% !");
}
System.out.println ("[1] Play again \n[2] Quit");
play = scan.nextInt();
}
//Quits Program
if (play == 2){
System.exit(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment