import java.util.*;
public class guangli {
public static void main(String[] args)throws Exception
{
Spgl aa=new Spgl();
Scanner in=new Scanner(System.in);
try
{
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 bh=in.next();
System.out.println("请输入食品名称");
String mc=in.next();
System.out.println("请输入食品的价格");
float jg=in.nextFloat();
Sp sp=new Sp(bh,mc,jg);
aa.addSp(sp);
}
else if(number.equals("2"))
{
System.out.println("请输入食品的编号");
String bianhao=in.next();
aa.Spxx(bianhao);
}
else if(number.equals("3"))
{
System.out.println("请输入食品编号");
String bianhao=in.next();
System.out.println("请输入食品价格");
float jiage=in.nextFloat();
aa.Spxg(bianhao,jiage);
}
else if(number.equals("4"))
{
System.out.println("请输入要删除的食品编号");
String bianhao=in.next();
aa.Sprm(bianhao);
}
else if(number.equals("0"))
{
System.out.println("感谢您的使用");
System.exit(0);
}
else
{
System.out.println("输入有误");
}
}
}catch(Exception e)
{
System.out.println("输入有误");
}
}
}
class Sp
{
private String bianhao;
private String name;
private float jiage;
public String getBianhao() {
return bianhao;
}
public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getJiage() {
return jiage;
}
public void setJiage(float jiage) {
this.jiage = jiage;
}
Sp(String bianhao,String name,float jiage)
{
this.bianhao=bianhao;
this.name=name;
this.jiage=jiage;
}
}
class Spgl
{
private ArrayList A=null;
Spgl()
{
A=new ArrayList();
}
public void addSp(Sp sp)
{
A.add(sp);
System.out.println("添加食品成功");
}
public void Spxx(String bianhao)
{
int i=0;
for(i=0;i<A.size();i++)
{
Sp b=(Sp)A.get(i);
String bh=b.getBianhao();
if(bh.equals(bianhao))
{
System.out.println("食品的编号为:"+bh);
System.out.println("食品名称为:"+b.getName());
System.out.println("食品价格为:"+b.getJiage());
break;
}
}
if(i==A.size())
{
System.out.println("输入有误查无此物");
}
}
public void Spxg(String bianhao,float jiage)
{
int i=0;
for( i=0;i<A.size();i++)
{
Sp b=(Sp)A.get(i);
if(b.getBianhao().equals(bianhao))
{
b.setJiage(jiage);
System.out.println("修改成功");
break;
}
}
if(i==A.size())
{
System.out.println("输入有误查无此物");
}
}
public void Sprm(String bianhao)
{
int i=0;
for(i=0;i<A.size();i++)
{
Sp b=(Sp)A.get(i);
if(b.getBianhao().equals(bianhao))
{
A.remove(i);
break;
}
}
if(i==A.size())
{
System.out.println("输入有误查无此物");
}
}
}