Consider a bank where you have to register the name of the holder and the balance of all bank accounts. The bank accounts may be of the type "Current account" or "Longterm account".
When we calculate interest rates on accounts, it's useful to have a listing of all the accounts and print the interest rates of each.
To calculate interest rates for each account follow these rules:
- Current accounts has an interest rate of 1%
- Longterm accounts has an interest rate of 2% if the balance is less than 2000 USD and 3% otherwise.
1 - The aim is to create a hierarchy of classes and a test program that will generate a listing of interest rates on all bank accounts. There must be no duplicate variables in various classes (eg, each account can only have one balance).
The expected outcome of the program is a listing similar to:
Current Account: Amos Leon, balance: 100 USD, interest: 1 USD
Current Account: Lindsey Le, balance: 1000 USD, interest: 10 USD
Longterm Account: Fredrick Trevino, balance: 1000 USD, interest: 20 USD
Current Account: Bette Cole, balance: 5000 USD, interest: 50 USD
Longterm Account: Bernardo Schultz, balance: 5000 USD, interest: 150 USD
2 - The marketing department of the bank proposed to create a new account called "Savings Account", which is an account of the Longterm, but when the balance is over 1000 USD and less than 2000 USD, has an interest rate of 2.5%. Do this without changing existing classes in the hierarchy of accounts and test it joining 2 new Saving accounts to the existing accounts.
3 - Create and test a mechanism for making deposits and withdrawals (ie change the balance of accounts) with the following rules:
- In Current accounts, may be deposited and lifted any value as long as the balance allows it (ie keeping the balance greater than or equal to zero).
- In Longterm accounts may be deposited only values above 1000 USD and can be withdraw, any value as long as the balance allows it (ie keeping the balance greater than or equal to zero).
- On Savings accounts may be deposited values and multiples of 1000 USD and can be withdraw any value as long as the balance allows it (ie keeping the balance greater than or equal to zero).
The code that implements each of the above rule must be within the class of the account to which the rule relates.
Failing to deposit or withdraw the accounts should remain in the state prior to attempting to deposit or withdraw.
It must not be possible to make deposits or withdrawals of negative values.
This challenge should be done in Eclipse with Java 1.6. The input and output is done trough console (no graphical interface whatsoever). It should use basic Java concepts, such as:
- Class, Class extends, abstract Class, Enumerator
- Exceptions and Errors