展开全部
32313133353236313431303231363533e4b893e5b19e31333337623535
packagesum;
importjava.util.ArrayList;
importjava.util.Scanner;
publicclassTestDemo{
publicstaticvoidmain(String[]args){
ArrayListarr=newArrayList();
Goodsg1=newGoods(1,"羽毛球",237);
Goodsg2=newGoods(2,"羽毛球拍",113);
Goodsg3=newGoods(3,"护腕",100);
arr.add(g1);
arr.add(g2);
arr.add(g3);
System.out.println("***********************商品查询系统*********************");
System.out.println("1.羽毛球2.羽毛球拍3.护腕");
System.out.println("*****************************************************");
Scannersc=newScanner(System.in);
outer:while(true){
System.out.print("请选择商品号:");
Stringnum=sc.next();
for(inti=0;i
if((arr.get(i).getId()+"").equals(num)){
System.out.println(arr.get(i).getName()+""+arr.get(i).getPrice()+"元");
}elseif(num.equals("n")){
System.out.println("谢谢使用");
breakouter;
}
}
}
}
}
classGoods{
publicGoods(intid,Stringname,intprice){
this.id=id;
this.name=name;
this.price=price;
}
privateintid;
privateStringname;
privateintprice;
publicintgetId(){
returnid;
}
publicvoidsetId(intid){
this.id=id;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetPrice(){
returnprice;
}
publicvoidsetPrice(intprice){
this.price=price;
}
}
很辛苦写的希望能采纳
java商品类别如何与价格对应_java编写程序实现某超市商品查价功能。从键盘输入商品号 显示对应的商品价格 以“n”结束查询。...