/* filename: Paycheck.java description: collects name and income and calculates taxes author: Kalin Ringkvist, k.rainquist@comcast.net version: 1.00 2004-01-12 */ //import the package so we can use the BufferedReader, string and util classes import java.io.*; import java.text.*; import java.util.*; public class Paycheck { public static void main(String[] args) throws IOException { //declare number variables to represent deduction percentages or amounts double incomeTax = 0.15; double stateTax = 0.035; double socTax = 0.0575; double medTax = 0.0275; double pension = 0.05; double health = 75; if health == 75 pension = 50; /*instantiate the BufferedReader, printwriter, stringtokenizer and decimalformat classes*/ BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); PrintWriter results = new PrintWriter(new FileWriter("results.txt")); StringTokenizer tokenizer; DecimalFormat money = new DecimalFormat("0.00"); //declare 1 string variable for employee name and 7 double variables for amounts String name; double yourGross, yourIncomeTax, yourStateTax, yourSocTax, yourMedTax, yourPension, yourPay; //obtain the users first/last name and gross income and separate/concatenate them into variables System.out.println("Enter name (first and last) followed by a space, then enter the gross:"); tokenizer = new StringTokenizer(keyboard.readLine()); name = tokenizer.nextToken() + " " + tokenizer.nextToken(); yourGross = Double.parseDouble(tokenizer.nextToken()); //calculate individual tax amounts for employee yourIncomeTax = incomeTax * yourGross; yourStateTax = yourGross * stateTax; yourSocTax = yourGross * socTax; yourMedTax = yourGross * medTax; yourPension = yourGross * pension; //subtract all taxes and deductions from total pay yourPay = yourGross - health - yourPension - yourMedTax - yourSocTax - yourStateTax - yourIncomeTax; //print results to results.txt file using separate println commands because "/n" didn't work results.println(" " + name); results.println("Your Gross: $" + money.format(yourGross)); results.println("Your Income Tax: $" + money.format(yourIncomeTax)); results.println("Your State Tax: $" + money.format(yourStateTax)); results.println("Your Social Security Tax: $" + money.format(yourSocTax)); results.println("Your Medicare tax: $" + money.format(yourMedTax)); results.println("Your Pension payment: $" + money.format(yourPension)); results.println("Your health payment: $" + money.format(health)); results.println("Your Net Pay: $" + money.format(yourPay)); results.close(); } }