Package de.hdm_stuttgart.mi.sd1.interest
Class Account
java.lang.Object
de.hdm_stuttgart.mi.sd1.interest.Account
Dealing with account balances and interest calculations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Convenience method to {applyInterest(int)
}: Adding one year's interest to the current balance according to:void
applyInterest
(int years) Adding the accumulated interest of a given number of years to the current balance according to:static double
double
static double
double
Calculate the expected annual interest without changing the account's balance.static void
setAssetInterestRate
(double assetInterestRate) Setting the interest rate common to all accounts.void
setBalance
(double balance) Setting a (possibly) new balance.static void
setDebtInterestRate
(double debtInterestRate) This interest rate will be applied to negative balances.
-
Constructor Details
-
Account
public Account()Create a new account having a balance of 0. -
Account
Create a new account of given initial balance.- Parameters:
balance
- The account's initial balance.
-
-
Method Details
-
getBalance
- Returns:
- The account's current balance.
-
setBalance
Setting a (possibly) new balance.- Parameters:
balance
- The desired new balance value. If greater than 10000 a warning message is being issued and the accounts current value will be retained.
-
setAssetInterestRate
Setting the interest rate common to all accounts. This one will be applied to positive balances only. For handling negative balances see {setDebtInterestRate(double)
.- Parameters:
assetInterestRate
- The desired (global) interest rate.
-
getAssetInterestRate
- Returns:
- The current global interest rate
-
getDebtInterestRate
- Returns:
- The debt interest rate value.
-
setDebtInterestRate
This interest rate will be applied to negative balances. In contrast {setAssetInterestRate(double)
will handle positive balance values.- Parameters:
debtInterestRate
- The debt interest rate's value.
-
applyInterest
Convenience method to {
\[ balance_{1} = balance (1 + {interestRate\over 100}) \]applyInterest(int)
}: Adding one year's interest to the current balance according to: -
applyInterest
Adding the accumulated interest of a given number of years to the current balance according to:
\[ balance_{years} = balance\ {\left(1 + {interestRate\over 100}\right)}^{years} \]Positive balances will receive the value of
setAssetInterestRate(double)
whereas calculation of negative balances will be based on {setDebtInterestRate(double)
.- Parameters:
years
- the given time period.
-
getYearlyInterest
Calculate the expected annual interest without changing the account's balance.- Returns:
- Annual interest to be expected
-