所以我在研究订购Items
java项目。 但是,在我的代码中,似乎不应该重复标记的术语并将其分配给自定义Items类的值。
代码:
publicvoidtokenizeterms (字符串内容) {
string [ ] tokenized terms=content.split (' ';
item [ ] item array=newitem [ tokenized terms.length/3 ];
Item fillItem=new Item (;
文件item.set name (fill item );
fillitem.setprice(0.00;
fillitem.setquantity(1;
Arrays.fill(ItemArray,fillItem );
int currToken=0;
for(intI=0; i itemArray.length; I ) {
item array [ I ].set name (tokenized terms [ curr token ];
currToken;
try {
int foo=integer.parseint (tokenized terms [ curr token ];
itemarray[I].setquantity(foo );
currToken;
双精度moo=double.parse double (tokenized terms [ curr token ];
itemarray[I].setprice(moo;
currToken;
}catch(exceptione ) {
system.out.println (errorparsingdata.';
}
}
this.items=itemArray;
}
项目类别:
公共类项目{
私有字符串名称;
保密质量;
私密双保密;
公共语音集名称(字符串名称) {
this.name=name;
}
公共字符串getname
return this.name;
}
公共语音质量(int quantity )。
this.quantity=quantity;
}
公共插入获取质量
return this.quantity;
}
publicvoidsetprice (双精度) {
this.price=price;
}
公共双获取
return this.price;
}
}
通过运行tokenize terms方法并在itemArray中打印每个项目的值,可以获得一组这样的项目。
名称:图书数量: 14价格: 856.89
名称:图书数量: 14价格: 856.89
名称:图书数量: 14价格: 856.89
但我知道这不应该发生。 因为String [] tokenizedTerms看起来是这样的:
[CD,32,459.2,叔,22,650.8,Book,14,856.89 ]