Create class that implements BankAccount interface. Your task is to write that class. The primary task of the BankAccount object is to keep track of the account balance. However, different accounts may earn interest at different rates, so the object must also track its own interest rate. The BankAccount class should has three constructors:
- one takes an initial balance and an interest rate;
- one takes just the initial balance (the interest rate is set to the default interest rate, which is 1.0%);
- one takes no arguments (the balance is set to $0.00, and the interest rate to the default).
Each BankAccount object is assigned an account number in the order that it was created. That is, the account number for the first account is 1, for the second account 2, and so on. This account number is available through the instance constant ACCOUNT_NO. BankAccounts also have the following methods:
- getBalance - returns the balance in this account;
- getRate - returns the rate for this account;
- withdraw - takes money out of the account -- but only if there's enough money in the account to cover the withdrawal;
- deposit - adds money to the account;
- addInterest adds interest to the account. It adds one year's interest to the account (at the account's individual interest rate). For example, if the balance is $1000.00 and the rate is 10%, then addInterest() increases the balance to $1100 ($1000 plus 10% of $1000);
- setRate - changes the interest rate on this account;
- toString - returns a String representing this account. The String is of the form "Account #N, ($bbb.bb)", where N is the account number and bbb.bb is the account balance. Balance must have exactly two digits after the decimal with DOWN rounding.
Implement TransactionalBankAccount interface. There are several additional things:
- setAutoCommit - determine whether each specific operation is automatically committed (can't be reverted);
- commit - when auto commit is disabled, commits all changes;
- revert - when auto commit is disabled, revert all uncommitted changes.
Feel free to use BankAccount implemented in previous task.
As soon as we have TransactionalBankAccount it's not very convenient to execute bunch of operations in one transaction. Implement AccountTransactionManager which allows to execute several operations at once. There two methods:
- execute - executes array of operations. Do not guaranty that all operations are executed without errors and do not revert previous operations in case of errors.
- executeInTransaction - executes array of operations in transactions. Guaranty that ALL operations are executed or none of them (in case of any error). Should disable autoCommit after execution.
There are several classes which describe Cafe. Cafe serves Clients giving them coup of some kind of drink. Client has one method drinkCoffee with one argument Drink. If a drink is not a coffee - one exception should be thrown by Client. It should be handled by the Cafe and another drink given to Client. If coffee is too cold - second exception should be thrown by Client. It should be handled by the Cafe and coffee should be warmed up. If coffee is too hot - third exception should be thrown by Client. It should be handled by the Cafe and coffee should be cooled. Client can be very unsatisfied by any other reason (random) and fourth exception should be thrown by Client. It that case Cafe can't serve Client and exception should be thrown.
Create own exceptions hierarchy. Determine which exception should be thrown in each case. Exceptions should have information about temperature if Coffee was too cold or too hot. Print to console every exception that was handled.
There is an App class that creates Cafe and generates Clients which Cafe should serve.