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:
|~ztomasze Index :
TA Details: ICS211:
|Last Edited: 17 Nov 2003|
©2002 by Z. Tomaszewski.