Exercise 3: Creating a Batch Program (Advanced)
In
this exercise, you will create a batch program to accumulate interest for each savings account on a monthly basis.
Note
- This is an advanced exercise. This exercisie is optional and should
only be attempted if you completed all of the previous exercises for
this module.
Figure 6-3 shows the dependencies between the class used by the TestBatch program.
Preparation
Before
you begin, make sure that you have changed directories to projects/BankingPrj/ using the
cd
command in the terminal de window.
cd ~/ projects/ BankingPrj/
Task
1 - Modifying the SavingsAccount
Class
A
savings account gains interest. The bank permits customers to store
money in a savings accoun and, on a monthly basis, the savings account
will accumulate based on the following formula: balance = balance +
(interestRate * balance). Add the acculateInterest method to perform
this operation.
Task
2 - Creating the AccumulateSavingsBatch
Class
Perform the following:
- Make the src/com/mybank/batch/
directory.
- Using a text editor,
create the AccumulateSavingsBatch.java code. Here is the pseudo-code for
the doBatch method:
for each Customer in the Bank do
for
each Account in the Customer do
if
the Accunt is a SavingsAccount,
then
call the accumulateInterest method
Task
3 - Copying the TestBatch
Class
Copy
the
TestBatch.java file from the resources/mod06_class1/ directory into the src/com/mybank/test/ directory
Task
4 - Compiling the TestBatch Class
On
the command line, use the javac
command to compile the test program.
Task
5 - Running the TestBach
Program
On
the command line, use the java
command to run the test program.
You should see the following output.
CUSTOMERS
REPORT
================
- Customer: Simms, Jane
- Savings Account: current balance is 500.0
- Checking Account: current balance is 200.0
- Customer: Bryant, Owen
- Checking Account: current balance is 200.0
- Customer: Soley, Tim
- Savings Account: current balance is 1500.0
- Checking Account: current balance is 200.0
- Customer:
Soley, Maria
- Checking
Account: current balance is 200.0
- Savings
Account: current balance is 150.0
- ACCUMULATE SAVINGS BATCH EXECUTED
CUSTOMERS
REPORT
================
- Customer: Simms, Jane
- Savings Account: current balance is 515.0
- Checking Account: current balance is 200.0
- Customer: Bryant, Owen
- Checking Account: current balance is 200.0
- Customer: Soley, Tim
- Savings Account: current balance is 1612.0
- Checking Account: current balance is 200.0
- Customer:
Soley, Maria
- Checking
Account: current balance is 200.0
- Savings
Account: current balance is 157.5