Assignment 8: Banking on Java


The goal of this assignment is for you to practice file input and output, arrays, and methods.  This assignment is very similar to what we did in lab since it is possible that we won’t have time to finish in class. However pay close attention as there are differences! 

Part 1: Preparing to deal with multiple accounts and methods

The application you are writing will support the creation of new bank accounts.  Specifically it will make sure that a proposed new bank account number does not already exist (which it will determine by looking at the existing account numbers in a text file called accountsFile.txt) and will add the new number to accountsFile.txt.  (10 points) Please note that for this assignment, the user should be asked if he/she wants to enter another new account after the first one.  He/she should be able to add as many accounts as he/she wants.

We want to be able to deal with multiple account numbers stored in the same file, and we want to be able to read them all into our application to avoid going back and forth between the application and the file.  To do so we need to create an array of Strings which will eventually be filled with all the existing account numbers.  Please note that for this assignment you cannot count on a separate file containing the total number of bank accounts.  You will have to calculate the total number of accounts in some other way since you can only use the file accountsFile.txt containing the list of all account numbers currently used.

(20 points!) Write the JEnglish for a modification of the program that will perform the operations listed below.  Make sure you include in your JEnglish a full description of the methods you will need.  You’ve already done some of this work in class, and we discussed nearly all of it.  You should take this opportunity to think about making good use of your JEnglish.  Remember that JEnglish is NOT about making your teacher happy!  It may seem that way, be believe me, really thinking out what you are trying to accomplish, each specific step of it, makes your coding a lot easier, cleaner and WILL ultimately save you time.  For full points, your description of the exact purpose each method must also be clearly specified.

Review the slide from my notes where I showed you my version of the main() method and you should get an idea of how you might break the steps up into methods that will achieve the steps described below.  Not every one of these has to be an individual method—although it’s pretty close. Still, how you organize it is ultimately up to you.    

You should structure your JEnglish to mimic the final program, including a list of "method calls" on top and details about each method at the bottom.  For each method, write some details about what parameters it will need, what if any value it will return, and clearly specify what the method actually does. Again, not about making teacher happy.  It’s about saving student time!

Part 2: Dealing with multiple accounts and methods

(5 points) The main() method:  Your main method needs to be very short.  It should be a handful of method calls and possibly a loop (again, see my version of main() from the class slides).  You have some freedom on how you implement the solution; however, you should create at least the four methods listed below.  If your solution requires you to change the parameters slightly, you can do that, but make sure you read through and can handle Item 5 below by changing only one or two lines of code.

  1. (10 points) Create a method called getTotalNumberOfAccounts that has a String as a parameter.  The String represents the name of the text file where the account numbers are stored.  It returns an int which represents the total number of accounts (lines) in the file.
  2. (10 points) Create a method called loadAccounts that accepts an int and a String as parameters.
    1. The int represents the total number of accounts that exist.  You need to figure out how to get that value. (see previous step!)
    3. The method will return an array of Strings.
    4. Each spot in the returned array will contain one bank account number (or one line of the file in which such account numbers are stored)
  3. (15 points) Create a method called getNewAccount that takes an array of Strings as a parameter and returns a new valid account number.  An account number is considered valid if it is different from all existing account numbers, which are stored in the array parameter to the method.
  4. (15 points) Create a method called addAccount that will add the new account number to the appropriate file (accountsFile.txt in this case).  This method accepts two Strings, an array of Strings, and an int as parameters and has no return value.
    1. The first String represents the name of the text file where the account numbers are to be stored.  When you call the method, this parameter will have the value "accountsFile.txt".
    2. The second String holds the new account number that is to be added to the text file.
    3. The array of Strings holds all previously existing account numbers.
    4. The int represents the new total number of accounts.
    5. The method will add the new account number to the file where all existing account numbers are stored.

Part 3: How was it?

(5 points) Create a short ReadMe Word or text file (ReadMe.doc or ReadMe.txt) containing the following information:

  1. Your full name
  2. Class, section, and homework number
  3. A couple of paragraphs describing the main difficulties encountered when completing this assignment as well as the aspect that was the most fun.  Make sure to include both the difficulties and the enjoyable aspect in your description.

There are 10 points not accounted for in the point totals listed above.  These points are for miscellaneous aspects like following submission instructions, naming variables properly, commenting your code, formatting your code effectively, etc.

Submitting the assignment

As always, you must submit the assignment using the online homework submission system on the COL site.  Create a .zip file with the necessary documents from each part of the assignment and upload this file to the COL site.  The .zip file should be called where yourLastName is your last name and should contain the following items:

  1. A file with the JEnglish/pseudocode version of your solution
  2. A folder containing your BlueJ project, or if you are using another IDE, the .java file that contains your source code
  3. The ReadMe file with your reflection on the assignment

Be warned that even if you include text files that you used for testing, I am likely to use my own text files when running your program.  Make sure that you stick to the format discussed here since a program that crashes or malfunctions when I run it on a text file following the assumed format will not earn full credit.

Late assignments are NOT accepted for this assignment.