Stacks和ArrayList [英] Stacks and ArrayList

查看:76
本文介绍了Stacks和ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



假设我们之前已经定义了以下类StockPurchase,它具有以下实例变量

a)股票的名称(一个字符串)

b)股票的股票数量(一个整数)

c)购买价格(可以是小数)



Part-2)编写一个名为ManageMultipleStocks的类及其相应的驱动程序。您的程序应允许用户输入有关各种股票购买的信息:他们的名字,股票数量和价格。然后,用户可以根据一定数量的股票的LIFO或FIFO会计方法输入关于给定股票成本的查询。

ManageMultipleStocks可以使用以下方法:

void addStockPurchase(StockPurchase sp);

double getLIFOCost(String stockName,int numShares);

double getFIFOCost(String stockName,int numShares);


提示:ManageMultipleStocks将包含一组堆栈(ObjectStack的Vector或ArrayList)和一组队列(ObjectQueue的Vector或ArrayList)。您可能还有ManageMultipleStocks包含ManageSingleStock对象的集合。






我的问题只是对问题的解释,为什么我们需要在这里使用ArrayList并在addStockPurchase(StockPurchase sp)中我们必须做ArrayList list = new ArrayList();

list.add(sp) ;


我不需要代码我只需要解释一下这个问题。

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 ManageMultipleStocks 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 ManageMultipleStocks could have the following methods:
void addStockPurchase(StockPurchase sp);
double getLIFOCost(String stockName, int numShares);
double getFIFOCost(String stockName, int numShares);

Hint: ManageMultipleStocks 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 ManageMultipleStocks contain a collection of ManageSingleStock objects.







My question is just an explaination of the problem and why do we need to use ArrayList here and in addStockPurchase(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.

推荐答案


大家好。



假设我们之前已经定义了以下具有以下类别的StockPurchase作为实例变量

a)股票的名称(一个字符串)

b)股票的股票数量(一个整数)

c)购买价格(可以是小数)



Part-2)编写一个名为ManageMultipleStocks的类及其相应的驱动程序。您的程序应允许用户输入有关各种股票购买的信息:他们的名字,股票数量和价格。然后,用户可以根据一定数量的股票的LIFO或FIFO会计方法输入关于给定股票成本的查询。

ManageMultipleStocks可以使用以下方法:

void addStockPurchase(StockPurchase sp);

double getLIFOCost(String stockName,int numShares);

double getFIFOCost(String stockName,int numShares);


提示:ManageMultipleStocks将包含一组堆栈(ObjectStack的Vector或ArrayList)和一组队列(ObjectQueue的Vector或ArrayList)。您可能还有ManageMultipleStocks包含ManageSingleStock对象的集合。






我的问题只是对问题的解释,为什么我们需要在这里使用ArrayList并在addStockPurchase(StockPurchase sp)中我们必须做ArrayList list = new ArrayList();

list.add(sp) ;


我不需要代码我只需要解释一下这个问题。
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 ManageMultipleStocks 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 ManageMultipleStocks could have the following methods:
void addStockPurchase(StockPurchase sp);
double getLIFOCost(String stockName, int numShares);
double getFIFOCost(String stockName, int numShares);

Hint: ManageMultipleStocks 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 ManageMultipleStocks contain a collection of ManageSingleStock objects.







My question is just an explaination of the problem and why do we need to use ArrayList here and in addStockPurchase(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.



任何建议或帮助也很有用!!

Any suggestions or help is also helpful!!


首先需要这两行来初始化ArrayList所以它可以是用于和第二个将对象添加到列表中。也就是说,我质疑为什么第一行是在方法而不是它所属的构造函数。
You need those two lines first to initialize the ArrayList so it can be used and second to add the object to the list. That said, I question why the first line is in the method rather than the constructor, where it belongs.


要查看和阅读的几点是:

ArrayList vs array

ArrayList vs Vector


谷歌那些。它们应该是一个很好的起点。
A few points to look up and read about are :
ArrayList vs array
ArrayList vs Vector

Google for those. They should be a good starting point.


这篇关于Stacks和ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆