Our new bank needs a teller transaction system but there is a problem. There is only a few hundred bytes of space left on our server, so you will have to write very compact code.
Database
Thankfully our database is very simple (it was built by the schoolboy son of our bank president), and we only have a few customers so far.
file Bank.data
is:
Account Firstname Lastname Balance Date
123 Maree Jones 346.22 2014-12-13
035 Thomas Breakbone 3422.02 2015-01-03
422 Henrietta Throsby-Borashenko 277847.74 2014-11-21
501 Timmy Bongo 7.95 2014-11-04
105 William Greene 893.00 2015-01-06
300 Mary Galoway 1228.73 2014-12-28
203 Samantha Richardson 2055.44 2014-11-01
151 Bruce Wayne 956119.66 2014-10-09
166 Chip Stonesmith 266.71 2014-12-15
888 Alexandria Cooper 1299.82 2014-12-30
Application Specification
Our bank application must implement the following commands:
open <firstname> <lastname>
Creates (opens) a new account printing a unique 3 digit account number.
withdraw <account> <amount>
Withdraw amount from an account.
deposit <account> <amount>
Deposit amount into an account.
close <account>
Close account if empty.
report <fieldname>
Print a report of the database sorted by fieldname. Move the fieldname column
to the first position. Each column width will be the maximum of the widest data
and fieldname width, separated by one space. The first line will be the field
titles. The balances only must be right justified with a leading $
sign.
print <account>
Print the fieldnames and record for this account formated like the report.
Each time a record is changed, the Date
field in the record must be updated to
the current date.
The application will show a "# " prompt when waiting for a command. If a command fails (such as an operation on an unknown account or insufficient funds), the application must print the informative error message "failed". The program must write changes back to the file after each change, and read from the file on each command as there are many teller programs around the world operating on the file concurrently (we don't need file locking - that may reduce performance).
EDIT: String fields are simple ASCII (a-z,A-Z,-) without white space and the amount will always be between 0.00 and 1000000000.00 (1 billion) dollars with 2 decimal places indicating cents. The date will be in local time at each branch (a simple solution but may lead to some problems later...).
Output
Answers will need to demonstrate that they meet the specification. Please attach the output from your program after processing the following commands:
report Balance
open Clark Kent
print 001
deposit 001 4530
withdraw 105 893
close 105
report Date
Ensure you use an original copy of the Bank.data
file given above.
Scoring
This is code-golf, so your score will be the byte count of your code. Standard loopholes are prohibited.
<firstname>
and<lastname>
and the range and precision of<amount>
? (E.g. there may be some optimisations which are possible if<amount>
always has exactly two decimal places - or you may want the program to be usable by the Middle Eastern branch, where most currencies use three decimal places). \$\endgroup\$<firstname>
and<lastname>
both only usea-zA-Z
, but even a simple statement that they never contain tab characters allows using TSV. If they could be any sequence of ASCII characters, some form of escaping or delimiting other than with a one-char delimiter is necessary. \$\endgroup\$