Hello, I have an assignment to create a Java application that receives an input string such as "buy 100 share(s) at $20 each;buy 50 share(s) at $25 each;sell 135 share(s) at $37 each". The code is supposed to return the capital gain/loss and is supposed to calculate it using a FIFO data structure. This would be calculated such as 100*17 + 35*10.
I have most of it coded, and everything is currently working up to the point of parsing each string (semi colon delimited) into the needed elements and adding them to a queue.
The problem I'm having is figuring out how to remove the elements in a way that calculates the capital gain/loss.
Does any one have any pointers of where to start with this algorithm?
Thanks in advance for any help you may have!
Tara
3 Replies - 422 Views - Last Post: 08 October 2012 - 03:13 AM
#1
Question: Calculate Stock Capital Gains/Losses using Java
Posted 07 October 2012 - 07:04 PM
Replies To: Question: Calculate Stock Capital Gains/Losses using Java
#2
Re: Question: Calculate Stock Capital Gains/Losses using Java
Posted 07 October 2012 - 08:18 PM
This program feels very unrealistic to me. The answer all depends on how you have your code setup.
#3
Re: Question: Calculate Stock Capital Gains/Losses using Java
Posted 07 October 2012 - 09:11 PM
Thank you for your reply, sorry if my post was confusing...I didn't do a very good job at explaining the problem/assignment.
I think I figured it out (I'm just getting an index error on my arraylist I'm using to track the buying and selling of shares).
If I can't figure out how to fix my code so I don't keep getting the error I will post another question.
Thanks again for taking the time to view and/or respond to my question.
Tara
I think I figured it out (I'm just getting an index error on my arraylist I'm using to track the buying and selling of shares).
If I can't figure out how to fix my code so I don't keep getting the error I will post another question.
Thanks again for taking the time to view and/or respond to my question.
Tara
#4
Re: Question: Calculate Stock Capital Gains/Losses using Java
Posted 08 October 2012 - 03:13 AM
So... it's just a queue.
Can't really offer more without code. Good luck.
total = 0 for 100: equeue 20 for 50: equeue 25 for 135: total = total + ( 37 - dequeue )
Can't really offer more without code. Good luck.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|