Skip to content

Instantly share code, notes, and snippets.

@LordNairu
Created February 9, 2014 22:56
Show Gist options
  • Save LordNairu/8907354 to your computer and use it in GitHub Desktop.
Save LordNairu/8907354 to your computer and use it in GitHub Desktop.
/**
* Calculates the amount of tax to deduct
* from gross monthly pay.
* No tax is taken on the first £375
* 10% is taken on the next £225
* and 23% is taken on what remains
* @param grossPay - An employees gross pay
*/
public void taxCalc(double grossPay) {
// variables to hold the tax and pay to be taxed respectively
double tax;
double taxablePay;
taxablePay = 0;
tax = 0;
// Prints total pay before taxation to screen
System.out.printf("Gross Pay before taxation: " + "£%.2f\n", grossPay);
// Subtracts £375, whatever remains can be taxed
taxablePay = grossPay - FIRST_TAX_TARIFF;
// Checks which tariff and calculates total taxation
if (taxablePay > 0 && taxablePay <= SECOND_TAX_TARIFF) {
tax = taxablePay * FIRST_TARIFF_PERCENTAGE;
} else if (taxablePay > 0 && taxablePay > SECOND_TAX_TARIFF) {
tax = SECOND_TAX_TARIFF * FIRST_TARIFF_PERCENTAGE;
taxablePay -= SECOND_TAX_TARIFF;
tax += (taxablePay * SECOND_TARIFF_PERCENTAGE);
}
// Subtracts total taxation from gross pay and prints to screen
grossPay -= tax;
System.out.printf("Gross Pay after taxation: " + "£%.2f\n", grossPay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment