Anda di halaman 1dari 2

MIS307

Fall 2015
Homework #3
30 Points
Assigned:
9/14/2015
Due:
9/23/2015 11:59pm
1. Read chapter 11 of Big Java 5th Edition and provide short answers to the following questions.
Submit your answers in a text document (plain text or Microsoft Word format, please).
a. What happens if you try to open a file for reading that doesn't exist? What happens if you
try to open a file for writing that doesn't exist?
b. How do you open a file on Windows whose name contains a backslash, like
C:\temp\output.dat using a String to contain the name? Show the sample code that
creates a new File object for the filename string for C:\temp\output.dat, and then the
following new Scanner object that opens the file for reading.
c. What is the difference between throwing an exception and catching an exception?
d. What can your program do with the exception object that a catch clause receives? Describe
at least two different things a program can do with an exception.

2. Write a program to satisfy the following programming problem:


a. Complete the BankTransactions program that applies a series of transactions to bank
accounts.
Its main() method uses the Bank class to manage a set of BankAccount objects.
The Bank class contains the ArrayList of BankAccount objects and print the bank
account balances after performing the following operations.
Complete the readBankAcounts() method in the Bank class to read account data
(integer account number and double balance) values from a text file, create a
BankAccount object from the account number & balance, and add the new bank account
into the Bank. The accounts.txt file contains lines like:
1001 10000.00
1012 2830.45
1027 3389.21
Complete the applyTransactions() method in the Bank class to read transaction lines
from the transactions file. Each line will have a word specifying the action (deposit,
withdraw, or transfer), followed by the account(s) and amount for the
transaction. The deposit and withdraw words are followed by one account number and
then the amount. The transfer word is followed by the account to transfer from, the
account to transfer to, and the amount to transfer. The transactions.txt file contains
lines like:
deposit 1001 100.00
withdraw 1027 15.00
transfer 1012 1001 100.00

withdraw 1012 50.00


When the program is finished, it prints the list of all the accounts and balances, like:
1001 10200.00
1012 2680.45
1027 3389.21
You will need to complete the readBankAccounts() and applyTransactions()
methods in the Bank.java class.
Test your program using the provided accounts.txt and transactions.txt files,
but be aware that we will test your program using different accounts and transactions files.
We will not test your program with invalid input data.


Please submit your assignment to BlackBoard. Attach the text document for question 1 and ALL of the
Java source files (BankTransactions.java, Bank.java, BankAccount.java) for question 2 to your
assignment. Be sure to click the "Submit" button after you attach the files to your submission!

Anda mungkin juga menyukai