I am trying to construct 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.
BreadLoaf 2.75 25
I need to divide a string like this into "Breadloaf" "2.75", and "25". And then go to the next line and do the same thing until it reads "*"
public class Store {
private ArrayList 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 not sure how to divide it up
以上就是How can I search through a scanner and divide a String by spaces?的详细内容,更多请关注web前端其它相关文章!