Last active
January 12, 2021 16:23
-
-
Save adenhaus/219960168a96663b6497178c6c69f42e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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