Homework 5, This one checks out better.
Short Description:
Write a program that will check the balance on a checking account.
Goals
When you finish this homework, you should have:
- Used methods
- Parsed input using indexOf and substring
Formal Description
Warning: There are restrictions and requirements on the final code. Please read the entire assignment. The intention is that you accomplish the above listed goals. If you do not follow the restrictions there will be sever penalties.
With your success from the last banking application, you have decided to write a full blown check balancing application. You can download a CSV file of the transactions in your checking account from your bank, and you want to :
- Display this in a more appealing format
- Check the bank's computation.
The file you download is in the following format:
- The first line
- contains the phrase "Starting Balance"
- A comma
- The starting balance for the period, a float
- Example: Starting Balance,45.00
- Each additional line but the last contain the following comma separated fields.
- A transaction number
- This is an integer.
- For checks (withdraws) this is the check number.
- For everything else it is a 0
- A date
- A transaction type, one of the following words :
- A comment
- For a withdraw it is the pay to name on the check.
- For a fee, it is the reason for the fee
- For a Deposit it may be blank.
- An amount
- Floating point number
- Added to the balance for deposit types
- Subtracted from the balance for other types
- Examples of normal lines:
- 1001,03/01/2025,Withdraw,Bob's Burger Bar,50.00
- 0,03/02/2025,Fee,Overdraft Fee,5.00
- 0,03/05/2025,Deposit,,100.00
- The last line contains
- contains the phrase "Ending Balance"
- A comma
- The starting balance for the period, a float
- Example: Ending Balance,90.00
So the file "checks.dat" might contain the following:
Starting Balance,45.00
1001,03/01/2025,Withdraw,Bob's Burger Bar,50.00
0,03/02/2025,Fee,Overdraft Fee,5.00
0,03/05/2025,Deposit,,100.00
Ending Balance,90.00
Some notes about the file:
- There are no errors in the file, with the possible exception of the final balance.
- It is in the proper format, all types are correct, all fields are present, all commas needed are there.
- The lines in the order required.
Your task is to read in and process this file. Do so by printing a running
report.
Print the beginning balance.
- The words "Beginning Balance"
- The starting balance, lined up with the balance column below, (24 spaces I think)
- Otherwise formatted as described below.
For each transaction print:
- The date, filling 10 spaces
- The transaction type filling 10 spaces (%10s in printf)
- The amount of the transaction
- Filling 10 spaces.
- Formatted to 2 decimal places.
- Deposits should be positive, deductions should be negative
- Do not include a $
- The balance after the transaction
- Formatted as the amount of the transaction.
At the end, print a final balance formatted as the amount of the beginning balance above. But use the words "Final Balance"
Finally, print a single line stating if your computed final balance matches the bank's final balance.
An example of the final output for the given input file would be:
Beginning Balance 45.00
03/10/2025 Withdraw 50.00 -5.00
03/02/2025 Fee 5.00 -10.00
03/05/2025 Deposit 100.00 90.00
Final Balance 90.00
The final balance is correct.
Notes:
- You must use several small methods. I intend for you to follow the pattern from week 10 lectures.
- You must parse the input with indexOf and substring.
- You may not use arrays, the split command, formatted scanners or any other advanced utilities to parse the input.
- You may use parameters if you wish, but you may also accomplish all tasks with class member variables.
Required Files
A single java file containing the solution to this problem.
Submission
Submit the assignment to the D2L folder Program 5 by the due date.