Created
February 1, 2019 15:30
-
-
Save menon92/6b1c96ce04f5ae3a4792ca3e2ee41335 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
class Account { | |
float principal; | |
float rate; | |
int daysActive; | |
int accountType; | |
public static final int STANDARD = 0; | |
public static final int BUDGET = 1; | |
public static final int PREMIUM = 2; | |
public static final int PREMIUM_PLUS = 3; | |
static final double BROKER_FEE_PERCENT = 0.0125; | |
public boolean isPremium() { | |
if (accountType == Account.PREMIUM || accountType == Account.PREMIUM_PLUS) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
float interestEarned( ) { | |
float years = daysActive / (float) 365.25; | |
float compoundInterest = principal * (float) Math.exp(rate * years); | |
return (compoundInterest - principal); | |
} | |
float calculateFee(Account accounts[]) { | |
float totalFee = 0; | |
Account account; | |
for (int i = 0; i < accounts.length; i++) { | |
account = accounts[i]; | |
if (account.isPremium()) { | |
totalFee += BROKER_FEE_PERCENT * account.interestEarned(); | |
} | |
} | |
return totalFee; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment