CSC 110 Bank Account Java Programming Assignment
For this program, you will be the creator of a class (in Part1) and later the user of the class (in Part2). You will have to be familiar with classes, methods, passing things in and out of methods, constructors, static data/methods, exception handling, interfaces, and “aggregate” classes.
You are to write a class called BankAccount, which will simulate a user’s bank account. You can use my Program5.java as the “driver” that will create instances and tell them to do things (through their methods).
Then you will add some code to the Program5.java to create other instances and tell them to do things.
The BankAccount class: this class should implement AccountInterface and have the following:
this(“classified”); CSC 110 Bank Account Java Programming Assignment
Write your BankAccount class and compile it (with the java.util.Date class as an “aggregate” class). Program5.java is used as a “driver” to create accounts and tell them to do things. The expected results from running Program5.java can be seen in ‘output.txt’.
Once your BankAccount class is working, add to the bottom of the “driver” program called Program5.java. Have it implement the following functionality inside main. Notice there are 4 sections (create/use 3 accounts and then ask the BankAccount how many accounts have been created). Put each of the 4 sections into a separate try-catch block; for each one make sure that every possible type of exception can be caught (either by having multiple catch blocks or by setting it up to catch every possible type of exception). You can just print the exception if it is caught. CSC 110 Bank Account Java Programming Assignment
Extra Credit (optional, 6 pts):
The variables that will hold money should be doubles (because of decimals). However, they will not automatically print out like money. After your program is working, make the following changes to have them print out like money.
System.out.println(“\tTotal income:\t\t” + theDeposit);
System.out.println( “\tTotal income:\t\t” + money.format(theDeposit));
Please note that negative numbers will come out with ( )’s instead of a minus sign. This is the way accountants do it and it is OK to leave it like this…
Extra Credit (optional, 6 pts)
Create a new class called IllegalWithdrawalException. Make it a subclass of RuntimeException. It will not need any data or methods (all will be inherited). It should have one constructor which accepts a single String as an argument. Have that constructor do the same thing as its parent’s constructor would do with the same String.
Once your IllegalWithdrawalException compiles, change the BankAccount code so that it throws a new IllegalWithdrawalException instead of an IllegalArgumentException for any of the bad conditions in the withdraw method.
Finally, go back to your Part2 and change the try-catch blocks everywhere so that they will also catch an IllegalWithdrawalException. You can do this either by adding another catch block to the existing code everywhere or by changing the catch blocks so that the same catch block will the IllegalArgumentExceptions, IllegalWithdrawalExceptions, and IllegalStateExceptions.
Comments and indenting:
At the top of the program (class) should be a short comment which describes its purpose. It should also have your name and class on a separate line.
In the code itself, indent inside the class and then again inside main. Indent inside while loops and for loops. Also indent inside if statements and the else part. Put a blank line and then a comment as needed to describe “sections” of code.
Finally, make sure that your variable names are meaningful. CSC 110 Bank Account Java Programming Assignment