3 Replies - 1468 Views - Last Post: 08 October 2012 - 03:13 AM Rate Topic: -----

#1 tbtucker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-October 12

Question: Calculate Stock Capital Gains/Losses using Java

Posted 07 October 2012 - 07:04 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Question: Calculate Stock Capital Gains/Losses using Java

#2 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

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.
Was This Post Helpful? 0
  • +
  • -

#3 tbtucker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-October 12

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
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5874
  • View blog
  • Posts: 12,754
  • Joined: 16-October 07

Re: Question: Calculate Stock Capital Gains/Losses using Java

Posted 08 October 2012 - 03:13 AM

So... it's just a queue.
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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1