Back to 211 Main Page

Mobius strip

Assignment 7

The Assignment


For the FIFO capital gain calculator, I strongly recommend you write a Queue ADT and then use that in your calculator. Also, I recommend you read in the list of transactions from a file. (Remember to specify in your documentation or usage message for your program what the format of the file needs to be.) Then work through the list of transactions. When you're done, report the capital gain or loss. (It'd also be very useful if you report what stocks are still owned).

A recommended way to do this: When you get a buy order, enqueue it in the stack (for this, you will need an object that holds the number of shares and the price at which they were bought). When you get a sell order, peek at the front of the queue. If there are enough shares there, subtract the number of shares sold from that object. Otherwise, if there are not enough shares in the front of the queue to complete the sell order, sell what shares are there and dequeue that bunch of stocks. Then check the new front of the queue to see if there are enough additional shares there to complete the sell order. Remember that if you ever get a sell order for shares you don't own, you should throw an exception to report the error. (This is a simple stock simulation; we're not selling on margin or anything. :) ).

For the bank sim, I strongly recommend using your Queue ADT and SortedList ADT. (It's pretty easy if you do.) Again, it's best to read the input in from a file. Add all the events to your sorted list, and then process each one, as described in the text book.


The above is simply the recommended way to implement the homework. However, you are required to test your code with the following cases. You can enter the case however you want: you can run it as an input file, you can enter the input by hand to your program, you can hardcode the test in the main method, or use some other method. But somehow--either by running your submitted program when I receive it or by reading an included report or comment--I want to know what results your program produced for the following cases:

Capital Gains Calculator (gain or loss for these 4 transactions):

1) buy 10 at $20  
2) buy 50 at $30
3) sell 10 at $40  

1) buy 10 at $20
2) buy 50 at $30
3) sell 10 at $10  

1) buy 10 at $2.50
2) buy 50 at $3.00
3) sell 30 at $3.50  

1) buy 10 at $40
2) buy 30 at $20
3) sell 50 at $10   

Bank Simulation (average wait time before starting transaction for these 2 sets of transactions):

arrival  length
time     of task
-------  ---------------
1         5
10        5
12        5  

arrival  length
time     of task
-------  ---------------
5         5
8         5
10        5
11        2
25        8  


This assignment will be out of 10 points. You will get points for the following:

2.5 - Your program compiles without error
1.5 - Good documentation and follows ICS Java Coding Standards.
See this note on documenting your code. Use descriptive variable names, use internal capitalization for names, consistently indent and space code, etc.
2.0 - Capital Gains Calculator
Calculates the total capital gains or losses using a FIFO accounting system for shares, as described in the assignment description.
3.0 - Bank Simulation
Runs a simulation of a bank, meaning that it somehow models people arriving, departing, and waiting in a queue. Determines the average time people wait before starting their transactions.
1 - Testing
You test your code with at least the above scenarios. (If you use file inputs to test the different cases, remember to mail me the input files with appropriate filenames.)

~ztomasze Index : TA Details: ICS211: Assignment 5
Last Edited: 17 Nov 2003
©2002 by Z. Tomaszewski.