When a sale is made, you will have to sell a specific quantity. When you get a Transaction from the list, it may or may not have enough quantity to cover the sale. In the easy case, the sale is the...
Type: Posts; User: jps
When a sale is made, you will have to sell a specific quantity. When you get a Transaction from the list, it may or may not have enough quantity to cover the sale. In the easy case, the sale is the...
How will the new version of the sell method look then?
Here is some reading on nested classes
The instructions said:
Any extra classes that you write should be included as
private nested classes. Any additional class methods should also be private.
So be sure to follow that guideline
In the current design you have two array lists.
Stocks.add(stock);
StockPrice.add(price);
In the proposed setup, you have only one list, and add items as such:
Stocks.add(new...
Something like that should work, ya. This way you end up with a single unit to store in the queue, and an easy way to get the purchasePrice associated with each purchase on an individual basis, and...
Creating a data type (new class) to store the data is much better practice than trying to maintain two different array lists in sync. What would happen if one list did not get updated?...Both lists...
The instructions are not clear that the first purchased are to be the first sold or not, so that could be up for debate.
So it seems to me I would make a class to represent a transaction, and store...
Can you post the instructions, I want to be sure I fully understand what should be done
No the method name does not change the result, it is just convention to have variable names describe the value they hold, and method names describe their purpose. It is in an attempt to make the code...
Be sure to use code tags when posting code, help can be found on the announcements page
public int sell(int x, int y)
x and y are poor variable names, they should describe the value they represent...
...and the code you have so far?
..so we have a starting point, I can not just write the code for you :)
Write out the math here and I will help you translate it into code
Use a class to store the item and the price.
What is it you are having problems with? working out the math or writing the code that performs the math?