import java.util.Scanner;
public class Q2P {
public void start(){
// User types in income to nearest dollar and program
// responds with tax owing, and tax as % of income
// Ignore the under $9,880 rebate
// Assume all income counts for the "under $38,000" rebate
// Show with, and without, student loan owing for the entire year
// Use double arithmetic for calculations, but..
// Display money amounts rounded to nearest dollar
// Make use of the following constants for the tax rates
final double LOW_TAX_RATE = 0.195;
final double MID_TAX_RATE = 0.33;
final double TOP_TAX_RATE = 0.39;
final double REBATE_RATE = 0.045;
final double PENALTY_RATE = 0.015;
final double LOAN_RATE = 0.1;
/* Note that a professional program would also use constants for the
various income levels, but that would make this exercise a bit
cumbersome for beginners */
//Scanner scanner = new Scanner(System.in);
// Get income from the user
System.out.print("Type in total income to nearest dollar: ");
String in = Keyboard.readInput();
//scanner.nextLine();
double income = Double.parseDouble(in);
double under38000 = Math.min(income, 38000);
System.out.println("On a income of: $" + Math.round(under38000));
double over38000 = Math.max(0,income - 38000);
System.out.println("On a income of: $" + Math.round(over38000));
double inBetween = over38000 - Math.max(0, income - 60000);
System.out.println("On a income of: $" + Math.round(inBetween));
double over60000 = Math.max(0, income - 60000);
System.out.println("On a income of: $" + Math.round(over60000));
// Calculate income tax
// find tax on income up to $38,000 at 19.5%
double under38000Tax = under38000 * LOW_TAX_RATE;
System.out.println(" Income tax is: $" + Math.round(under38000Tax));
// find tax on income between $38,000 and $60,000 at 33%
double inBetweenTax = inBetween * MID_TAX_RATE;
System.out.println(" Income tax is: $" + Math.round(inBetweenTax));
// find tax on income over $60,000 at 39%
double over60000Tax = over60000 * TOP_TAX_RATE;
System.out.println(" Income tax is: $" + Math.round(over60000Tax));
// Calculate tax rebate
// find rebate on income up to $9500 at 4.5%
double taxRebate = 9500 * REBATE_RATE;
// find penalty on rebate for income between $9500 and $38,000 at 1.5%
// income between $9500 and $38,000 = incomeOver9500 - incomeOver38000
double over9500 = Math.max(0, income - 9500);
System.out.printf("income = %.0f over9500 = %.0f over38000 = %.0f%n" +
"income between $9500 and $38,000 = %.0f%n",
income, over9500, over38000, over9500 - over38000);
double penaltyRebate = (over9500 - over38000) * PENALTY_RATE;
// calculate net rebate
double netRebate = (taxRebate - penaltyRebate);
// calculate total income tax
double totalUnder38000Tax = (under38000 - under38000Tax);
double totalInBetweenTax = (inBetween - inBetweenTax);
double totalOver60000Tax = (over60000 - over60000Tax);
// Calculate percentage of income
double percentUnder38000 = ((under38000 - totalUnder38000Tax) * 100);
double percentInBetween = ((inBetween - totalInBetweenTax) * 100);
double percentOver60000 = ((over60000 - totalOver60000Tax) * 100);
// Calculate student loan tax
double studentLoanTax = (income - 17160) * LOAN_RATE;
// Calculate total taxes, with and without loan;
double totalTax = (totalUnder38000Tax + totalInBetweenTax +
totalOver60000Tax - netRebate);
double totalTaxInclStudentLoan = (totalTax + studentLoanTax);
// Display tax owing and rates
// Use the method Math.round() to convert a double value
// to the nearest whole dollar value.
System.out.println(" With rebate of: " + Math.round(netRebate));
System.out.println(" Giving total tax of: " + Math.round(totalTax));
System.out.println(" Which is: " + Math.round(percentUnder38000) + " of income");
System.out.println(" Which is: " + Math.round(percentInBetween) + " of income");
System.out.println(" Which is: " + Math.round(percentOver60000) + " of income");
System.out.println("With a student loan:");
System.out.println(" Loan repayment is an additional: " +
Math.round(studentLoanTax));
}
public static void main(String[] args) { new Q2P().start(); }
}