输入时 以下划线做出区分,同时将输入的值赋给不同类型的name quantity 和price
private Product readProduct() throws IOException {
final String DELIM = "_";
String name = "";
int quantity = 0;
double price = 0.0;
/* PLACE YOUR CODE HERE */
System.out.print("Product [Name_Quantity_Price] :");
try
{
String s=new Scanner(System.in).next();
StringTokenizer st=new StringTokenizer(s,DELIM,true);[email=sdrzsun@163.com][/email]
name+=st.nextToken();
quantity=Integer.parseInt(st.nextToken());
price=Double.parseDouble(st.nextToken());
}
catch(NumberFormatException e)
{
e.printStackTrace();
}
return new Product(name, quantity, price);
}