import java.util.*;
public class F1 {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
Spgl shipin=new Spgl();
while(true){
System.out.println("请按提示选择以下功能");
System.out.println("添加食品请按1");
System.out.println("查找食品信息请按2");
System.out.println("修改食品价格请按3");
System.out.println("删除食品请按4");
System.out.println("退出请按0");
}
String number=in.next();//有红线
if(number.equals("1")){
System.out.println("请输入名称");
String name=in.next();
System.out.println("请输入价格");
int jiage=in.nextInt();
System.out.println("请输入编号");
int bianhao=in.nextInt();
Spxx spxx=new Spxx(name, jiage, bianhao);
shipin.tianjia(spxx);
}else if(number.equals("2")){
System.out.println("请输入编号");
int bh=in.nextInt();
shipin.chaxun(bh);
}
}
}
class Spgl{
private ArrayList aa=null;
Spgl(){
aa=new ArrayList();
}
public void tianjia(Spxx spxx){
aa.add(spxx);
System.out.println("添加成功");
}
public void chaxun(int bh){
int i;
for(i=0;i<aa.size();i++){
Spxx spxx=(Spxx)aa.get(i);
if(spxx.getBianhao().equals(bh)){//有有红线
System.out.println("该食品信息为:");
System.out.println("名称:"+spxx.getName());
System.out.println("价格:"+spxx.getJiage());
System.out.println("编号:"+spxx.bh);//bh有红线
break;
}else if(i==aa.size()){
System.out.println("没有这件商品");
}
}
}
}
class Spxx{
private String name;
private int jiage;
private int bianhao;
Spxx(String name,int jiage,int bianhao){
this.name=name;
this.jiage=jiage;
this.bianhao=bianhao;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getJiage() {
return jiage;
}
public void setJiage(int jiage) {
this.jiage = jiage;
}
public int getBianhao() {
return bianhao;
}
public void setBianhao(int bianhao) {
this.bianhao = bianhao;
}
}
|
|