Cosc 2006 -data structures - show your program to ta before


Array and Selection Sort

Please remember to read and follow the assignment requirements.

In this assignment, you will write a very simple data maintenance Java program for a bank. Some of the techniques used (arrays as data structures, selection sort) will be review from cosc1047, while others (searching) will be the material you are now covering (or you have learned). This program will likely be physically longer than you have written so far, so remember do implement it in a modular fashion- do a proper program design even though you don't have to hand your design in. Also remember to START THIS ASSIGNMENT SOON. DO NOT leave it until the last minute!

John's 24-Hour Bank and 1-Hour Dry Cleaning is a new institution that has just begun to offer banking (and cleaning!) services to the University community. Your program will (thankfully) deal with only the banking end of the business. Every client of the bank has a customer number, and can have several types of accounts: checking, savings, and mutual funds. The bank will store a record for each account consisting of a customer number (an integer) representing the owner of the account, an account type (a single char: C for chequing, S for savings, and M for mutual fund), and the balance of the account (a double). These are kept in three arrays-an array of customer numbers, an array of types, and an array of balances.

A sample of what this might look like appears below:

Customer Array

Type Array

Balance Array

102241

C

1.29

992944

S

22.50

992944

C

1.24

The entries in the array correspond to one another-for example, the first slot in all three arrays represent the fact that customer number 102241 has a chequing account with $1.29 in it. As is shown, the same customer number can appear several times, as customers can have more than one account. These are called parallel arrays, because the slots in each correspond, and the really important thing about parallel arrays is that if you shuffle around anything in one array, you have to perform the same shuffles to the others. For example, say we delete one particular account. If we remove the entry from the customer array, but not the others, nothing matches any more and the data is worthless.

Similarly, if we sort by balance, every data movement in the balance array must be duplicated in the others precisely, or once again the correspondence is lost. Since the array entries correspond to one another, we also need only keep track of the size (the number of entries used) once, since there will be the same number of entries in all three arrays.

Your banking system will not do terribly much (by banking system standards!). When you start the program, it will look for a text file called bank.txt, open it, and load the three arrays with the data contained there. You can assume that bank.txt will contain one entry per line- the first customer number, then the account type on the next line, and the balance on the next line, then the next customer number, and so on. The data will not be in any particular order, but you can assume all data for each account will be present (that is, there'll be no unmatching balances, etc.), and that the data will be error-free.

Your bank will hold a maximum of 200 accounts, but you do NOT know how many will be in the file (you'll have to count them as you read and keep track of the sizes of arrays).

Once you have the data read in, you will prompt the user on the screen to enter commands (single characters). We will ignore the usual database update commands (creating, deleting accounts, etc), and concentrate only on selecting and viewing data. The valid commands your system will support are S (Search for an account), P (Print Total Balances), and Q (quit). You should error check these to ensure that other letters are not accepted (just print an error message in such cases and prompt for the command again). Your system will accept S and P commands until eventually the user enters a Quit command, causing the program to terminate.

When processing the Print Total Balances command, you will need to first ensure that the arrays representing the accounts are sorted by customer number so that all accounts for a particular customer appear together. Print Total Balances should thus begin by calling a Selection Sort method that you must write. You will have to slightly alter the one you saw in class, because you are using parallel arrays here. Remember, you have to keep the correspondence between slots: this means that while you're sorting the customer numbers, you will have to perform identical swaps in all three arrays. After the array has been sorted, Print Total Balances will print ONE entry for each customer showing the TOTAL of ALL the accounts that customer has. You must only go through the arrays ONCE to do this, which shouldn't at all be a problem once the data's sorted.

A Search command will allow the user to search for an account by account number, type, or both. The routine to process a search command will prompt the user for a customer number and account type. The user can either enter a valid value for these, or enter 0 for an account number or X for an account type. An account number of 0 or an account type of X will be considered a "don't care" on the user's part, allowing the search routine to display multiple results. For example, searching for an account of 12345 and an account type of X will cause ALL accounts for customer number 12345 to be displayed, regardless of the type of account. If they entered 12345 and C, it would only display the chequing account, if there were one. Similarly, a 0 for an account number, and an account type of S would cause ALL savings to be displayed. A single search command should only go through the arrays ONCE, and you should not sort or otherwise re-arrange the arrays.

Data returned by a search or Print Total Balances should be displayed in a table format, showing the fields from all three arrays (that is, the customer number, account type, and balance for all "found" account entries). For a search, if no data is found, simply display a message indicating that. In general, data should be nicely formatted and columns should be labeled appropriately.

You do not need to have a GUI for your program.

Show your program to TA before or on due date, and hand in (at the same time) a printed copy of your program and the output of your program, using the test data posted on the website.

Attachment:- Assignment.rar

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Cosc 2006 -data structures - show your program to ta before
Reference No:- TGS01592005

Now Priced at $65 (50% Discount)

Recommended (93%)

Rated (4.5/5)