4 Banking
You are going to build a simple system of bank accounts. The program reads commands from input and executes them on the accounts (such as withdrawals, deposits, enrolling of new accounts, printing, etc.).
Your program should be able to perform the following commands. All amounts are integer numbers.
Interest calculations are rounded to the nearest integer.
print “name”: prints the data (name and balance) of the account with name “name” ;
printAll: prints all accounts;
enroll “name”: enrolls a new account under the name “name”;
the initial balance is 0;
deposit “name” “amount”: adds “amount” to the account of “name”;
you may assume that “amount” is positive;
withdraw “name” “amount”: subtracts “amount” from the account of “name”;
you may assume that “amount” is positive;
if the operation would result in a balance of less than -1000, the withdrawal is not performed;
stop: stops the program.
The following extensions should be provided:
Add a command "printRed" that prints the data of all accounts with a negative balance.
Add a command "interest rate" that adds interest to all positive accounts;
Rate is a floating point number (double) representing the percentage of the current balance that should be added;
for negative accounts, a fixed penalty of 10% is subtracted, even if the resulting balance would be less than -1000.
Make the program a little bit more robust and have it perform elegantly when the commands "print", "withdraw", and "deposit" are given with a "name" that does not exist in the accounts. No operation should be performed and the message "no such name ..." should be printed, where the given name should appear instead of the dots. Furthermore, the command "enroll" with a "name" that is already in the accounts should result in no operation and the message "... already enrolled".
Use the following design.
The class "Account" has objects that represent the accounts. Each object has a name and a balance (Dutch: saldo). Design methods for the class Account, including those that enable to comply with the requirement that instance variables of a class should never be accessed directly (mentioned in the code) outside the class.
Input is read and processed by an object of the class "CommandReader". You do not have to write this class. It is provided on the course’s web page. The central class is "Bank" that contains the accounts (an ArrayList). It has at least the following methods, each corresponding to a command:
void print(String name)
void printAll()
void enroll(String name)
void deposit(String name, int amount)
void withdraw(String name, int amount)
void printRed()
void interest(double rate)
4.1 Input
A list of commands in the format as specified above. You may assume that every command is complete, so, e.g., "deposit" is always followed by a string (the name of an account) and an integer number (the amount to be withdrawn), etc. Two features are added in "CommandReader" for your convenience. When a word(string) is input that is not a command, the rest of the input line will be ignored and the message "unknown command" will be output. Furthermore, command words are not case sensitive.
4.2 Output
See the description above.
The data of an account with name “piet” and balance 200 should be printed as follows.
Account of piet
balance: 200
The word balance should be preceded by 2 spaces.
When printAll is issued is and there are no accounts, one line is to be printed with the text: no accounts
When printRed is issued is and there are no accounts with a negative balance, one line is to be printed with the text: no negative balances
4.3 Example
Text in bold face is input.
enroll piet
print piet
Account of piet
balance: 0
deposit piet 100
enroll jan
withdraw jan 50
printall
Account of piet
balance: 100
Account of jan
balance: -50
withdraw piet 2000
printAll
Account of piet
balance: 100
Account of jan
balance: -50
stop