1
我正试图通过读取给定扫描仪中的物品来构建商店。构造函数必须重复(直到项目名称为*)从给定的扫描仪对象读取项目并将其添加到其库存。如何通过扫描仪搜索并用空格分隔字符串?
BreadLoaf 2.75 25
我需要一个像这样的字符串分为 “Breadloaf”, “2.75” 和 “25”。然后转到下一行并执行相同的操作,直到它显示“*”
public class Store {
private ArrayList<Item> inventory;
// CONSTRUCTORS
/*
* Constructs a store without any items in its inventory.
*/
public Store() {
}
/*
* Constructs a store by reading items from a given Scanner. The constructor
* must repeatedly (until item name is *) read items from the given scanner
* object and add it to its inventory. Here is an example of the data (that
* has three items) that could be entered for reading from the supplied
* scanner:
*/
public Store(Scanner keyboard) {
while(keyboard != null){
}
}
@vishal_aim不知道如何分割它 – JustaBreitGuy
它有帮助吗? http://docs.oracle.com/javase/6/docs/api/java/util/Scanner.html –