Review and practice all concepts from CPCS-202, as well as a small review of CPCS-203, with a focus on making classes and creating objects from these classes. Specifically, you will practice making an array of objects and manipulating/using the data inside the array. Finally, and VERY important, this program requires you to read from a file and write to a file (practice with File I/O). This is very important because all programs during the semester will use File I/O.
Samba will be opening a new branch inside FCIT, which will be called FCIT Samba (not reallythis is just the story of the assignment). The purpose of this program is to design a simulation of the FCIT Samba branch. Students can open accounts at FCIT Samba. They can make withdrawals, deposits, print statements, and more. Each FCIT student can open one bank account at FCIT Samba
You will write a program that will simulate normal activities of FCIT Samba.
During the program, the following things can occur (just as in a normal bank):
You will use File I/O to read input from a file and then print the output to a file. To be clear, you will read COMMANDS from an input file. Example commands are OPENACCOUNT, DEPOSIT, WITHDRAW, TRANSFER, FINDACCOUNT, CLOSEACCOUNT, TRANSACTIONREPORT etc. Then, depending on the command, you will either add a new account, deposit amount, withdraw amount, transfer amount, close account, etc.
But instead of printing to the console window (screen), you will need to print it to an output file.
You will read in input from a file, "FCITsamba.in". Have this AUTOMATED. Do not ask the user to enter FCITsamba.in. You should read in this automatically.
Note: a *.in file is just a regular text file. Also, a *.out file is a regular text file. Do not be scared by this. Instead of calling the input and output file as input.txt and output.txt, it is better for those files to have a good name. Therefore, the input file will be called FCITsamba.in and the output file will be called FCITsamba.out.
The first line of the file will be an integer representing the maximum number of accounts in the bank. The second line of the file will be an integer representing the maximum possible number of recorded transactions for any given day of the simulation. The third line of the file will be an integer, d, representing the number of days for the simulation. For each day, there will be an integer k on the first line, followed by k commands, with each command on a new line and followed by appropriate data (and this relevant data will be on the same line as the command).
Your program must output to a file, called "FCITsamba.out". You must follow the program specifications exactly. You will lose points for formatting errors and spelling.
A sample input file, with corresponding output file, can be found on the Moodle (the files have too many lines to paste here).
NOTE: These files do NOT test every possible scenario. That is the job of the programmer to come think up the possible cases and test for them accordingly. You can be sure that our graders will grade with very large input files, which are intended to, ideally, test all possible cases. It is recommended that you spend time thinking of various test cases and build your own input file for testing purposes.
Your program MUST adhere to the EXACT format shown in the sample output file (spacing capitalization, use of dollar signs, periods, punctuation, etc). The graders will use very large input files, resulting in very large output files. As such, the graders will use text comparison programs to compare your output to the correct output. If, for example, you have two spaces between in the output when there should be only one space, this will show up as an error even through you may have the program correct. You WILL get points off if this is the case, which is why this is being explained in detail. Minimum deduction will be 10% of the grade, as the graders will be forced to go to text editing of your program in order to give you an accurate grade. Again, your output MUST ADHERE EXACTLY to the sample output.
For this program, you will have four files. One file will contain main, and the other three files will be classes: FCITstudent, FCITsambaAccount, and FCITsambaTransaction. The class UML diagrams are on the last page of this write-up.
The first two lines of the input file are as follows:
You must read these values into appropriate variables (maxAccounts and maxTransactions).
Next, you will use these new values to make two new arrays:
To help you, here is the code to do this:
FCITsambaAccount[] accounts = new FCITsambaAccount[maxAccounts];
FCITsambaTransaction[] transactions = new FCITsambaTransaction[maxTransactions];
What do these lines do? They create an array of references. Note: each reference has a default value of null. Until now, we have NOT created any objects. For example, FCITsambaAccount objects are only created when we see the command OPENACCOUNT. At that time, a new FCITsambaAccount object will be created and the reference for that object will be saved in the appropriate location of the array.
The commands you will have to implement are as follows:
OPENACCOUNT Makes a new account which is added to the bank. The command will be followed by the following information all on the same line: ID, an integer representing the ID number of the student (also the account number for this account); firstName, the first name of the customer/student; lastName, the last name of the customer/student; and openingBalance, the initial amount of for this account.
When you read the OPENACCOUNT command, you must make a new object of type FCITsambaAccount. Next, you must scan the additional information (listed above) and save this information into the correct data members of the new object.
*Note: this array must stay in sorted order based on the accountNumber. So the account with the smallest accountNumber value will be at index 0, the account with the next smallest at index 1, and so on. Therefore, when you save the object reference into the array, you must first find the correct sorted index. After you find the correct insertion location, if there is no object at that location, then you can easily save the object reference at this index. BUT, IF there is an object at the index that you find, you must SHIFT that object, AND all objects to the right of it, one space to the right. This is how you make a new space in the array for the new object.
Example: if your array already has 6 account object references, from index 0 to index 5. And now you want to add a new account object reference at index 4 (based on the sorted location). Before you can add the new account object reference at index 4, you must SHIFT the account object references at index 4 and index 5 to index 5 and index 6. Basically you need to move them one position over to the right. Now, you have an empty spot at index 4 for the new account object reference.
PRINTBALANCE This command will be followed by an integer on the same line. This integer represents the account number of the account you must search for. You must perform a Binary Search on your array of FCITsambaAccount object references. If the account is found, you should print the required information for the account. (see output).
* There are many possibilities (no accounts at all, this account not found, etc.). See output file for exact scenarios.
**We will check your code to confirm you are using Binary Search. You will only earn the points for PRINTBALANCE if you use Binary Search.
DEPOSIT This command will be followed by an integer and a double on the same line. This integer represents the account number of the account and the double value represents the amount of money you need to deposit in the account.
WITHDRAW This command will be followed by an integer and a double on the same line. This integer represents the account number of the account and the double value represents the amount of money you need to withdraw from the account.
TRANSFER This command will be followed by two integers and a double on the same line. The first integer represents the account number of the account from which money will be deducted, while the second integer represents the account number to which money will be added. The double value represents the amount of money to be transferred.
See output for printing examples.
CLOSEACCOUNT This command will be followed by an integer. This integer represents the account number to be deleted.
*Note: this array must stay in sorted order based on the accountNumber. Again, you must take care of shifting!
Example: if your array already has 6 account object references, from index 0 to index 5. And now you want to remove an account object reference at index 3 (based on the sorted location). To remove account object reference at index 3, you must SHIFT the account object references at index 4 to index 3, index 5 to index 4, and index 6 to index 5. Basically you need to move them one position over to the left
TRANSACTIONREPORT This command will have no other information on the line. When this command is read, a report of all transactions, for that given day, will be printed to the output file. Please refer to sample output for exact specifications.
NOTE: When a new day beings, the transaction array must be empty and the variable numTransactions should be reset to zero.
*NOTE: Not all commands will result in a transaction. Transactions occur only with commands that change the balance (OPENACCOUNT, DEPOSIT, WITHDRAW, TRANSFER, and CLOSEACCOUNT).