Skip to content

Instantly share code, notes, and snippets.

@adenhaus
Last active January 12, 2021 16:23
Show Gist options
  • Save adenhaus/219960168a96663b6497178c6c69f42e to your computer and use it in GitHub Desktop.
Save adenhaus/219960168a96663b6497178c6c69f42e to your computer and use it in GitHub Desktop.
public class WithAbstractions {
int upClass = 500000;
int midClass = 100000;
int lowClass = 50000;
int taxMax = 0.45;
int taxMid = 0.30;
int taxMin = 0.15;
public static int balanceAfterTax(int moneyIn, int moneyOut) {
int balance = calculateBalance(moneyIn, moneyOut);
return calculateTax(balance);
}
public static int calculateBalance(int moneyIn, int moneyOut) {
return moneyIn - moneyOut;
}
public static int calculateTax(int balance) {
if (balance > upClass) {
return balance - balance * taxMax;
} else if (balance > midClass) {
return balance - balance * taxMid;
} else if (balance > lowClass) {
return balance - balance * taxMin;
} else {
return balance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment