Objective

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.

The Problem

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):

  • New accounts can be created. Note: when new accounts are added for the first time, they are initialized with an opening balance (given in the input file). It is guaranteed that newly added accounts will always have a positive balance.
  • A customer can request the balance on the account.
  • A customer can deposit any amount into his account.
  • A customer can withdraw money from his account (if the money is available).
  • A customer can transfer amount from his account into another account. In this case the balance of the former customer will be reduced, while the balance of the later customer will increased accordingly.
  • A customer can close his account.
  • A list of daily transactions can be printed.

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.

Input File Specifications

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).

Output File Specifications

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.

Sample and Output Files

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.

***WARNING***

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.

Implementation

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:

  • Line 1: the maximum number of accounts that can be in the bank
  • Line 2: the maximum number of transactions in a given day

You must read these values into appropriate variables (maxAccounts and maxTransactions).

Next, you will use these new values to make two new arrays:

  • An array of FCITsambaAccount object references
  • An array of FCITsambaTransaction object references

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.

Commands to Process (from Input File)

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 that the firstName, lastName, and ID of the student must be saved into an object of type FCITstudent. How do you do this? Look at the UML diagram for FCITsambaAccount. One of the data members is called student, and the data type for student is FCITstudent. The variable student is a reference variable, but as of now, it is simply pointing to null. Therefore, inside the constructor of FCITsambaAccount, you should make a new FCITstudent object and save that reference into the variable student.
  • Note also that there is a variable called ID inside the FCITstudent object, and there is also a variable called accountNumber inside the FCITsambaAccount object. These two variables should have the SAME valuethe ID of the student.
  • Each account will be unique. Meaning, the input file is guaranteed to not have duplicate account added to the bank via the OPENACCOUNT command. Finally, you must save the reference of this object inside the appropriate index of the student array.

*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.

  • You must search for the correct account in the accounts array and then deposit the money if the account as found.
  • There are many possibilities (no accounts at all, this account not found, etc.). See output file for exact scenarios.

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.

  • You must search for the correct account in the accounts array and then withrdaw the money if the account as found.
  • There are many possibilities (no accounts at all, this account not found, etc.). See output file for exact scenarios.

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.

  • You must search for the account and delete it from the system. Here, we will delete simply by saving a difference object reference in its place (see below).

*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).

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.