Hello everyone.
Assume that we have previously defined the following class StockPurchase that has the following as instance variables
a) The name of the stock (a string)
b) The number of shares of a stock (an int)
c) The purchase price (can be a decimal)
Part-2) Write a class called ManageMultipleS tocks and its corresponding driver. Your program should allow the user to enter information about purchases of various stocks: their names, the amount of shares, and the prices. The user can then enter a query about the cost of a given stock according to the LIFO or FIFO accounting methods for a certain number of shares.
The ManageMultipleS tocks could have the following methods:
void addStockPurchas e(StockPurchase sp);
double getLIFOCost(Str ing stockName, int numShares);
double getFIFOCost(Str ing stockName, int numShares);
Hint: ManageMultipleS tocks will have a collection of stacks (a Vector or ArrayList of ObjectStack) and a collection of queues (a Vector or ArrayList of ObjectQueue). You might also have ManageMultipleS tocks contain a collection of ManageSingleSto ck objects.
My question is just an explaination of the problem and why do we need to use ArrayList here and in addStockPurchas e(StockPurchase sp) do we have to do ArrayList list=new ArrayList();
list.add(sp);
I don't need the code I just need an explaination for the problem.
Assume that we have previously defined the following class StockPurchase that has the following as instance variables
a) The name of the stock (a string)
b) The number of shares of a stock (an int)
c) The purchase price (can be a decimal)
Part-2) Write a class called ManageMultipleS tocks and its corresponding driver. Your program should allow the user to enter information about purchases of various stocks: their names, the amount of shares, and the prices. The user can then enter a query about the cost of a given stock according to the LIFO or FIFO accounting methods for a certain number of shares.
The ManageMultipleS tocks could have the following methods:
void addStockPurchas e(StockPurchase sp);
double getLIFOCost(Str ing stockName, int numShares);
double getFIFOCost(Str ing stockName, int numShares);
Hint: ManageMultipleS tocks will have a collection of stacks (a Vector or ArrayList of ObjectStack) and a collection of queues (a Vector or ArrayList of ObjectQueue). You might also have ManageMultipleS tocks contain a collection of ManageSingleSto ck objects.
My question is just an explaination of the problem and why do we need to use ArrayList here and in addStockPurchas e(StockPurchase sp) do we have to do ArrayList list=new ArrayList();
list.add(sp);
I don't need the code I just need an explaination for the problem.
Comment