食品管理系统Java代码.doc
《食品管理系统Java代码.doc》由会员分享,可在线阅读,更多相关《食品管理系统Java代码.doc(5页珍藏版)》请在冰豆网上搜索。
importjava.util.ArrayList;
importjava.util.Scanner;
classFood{
privateStringname;//食品名
privateStringbianhao;
privatedoubleprice;
privateintreserves;
privateStringbirthdate;
privateintqualitydate;
privateintindex;
publicvoidsetName(Stringname){
this.name=name;
}
publicStringgetName(){
returnthis.name;
}
publicvoidsetBianhao(Stringbianhao){
this.bianhao=bianhao;
}
publicStringgetBianhao(){
returnthis.bianhao;
}
publicvoidsetPrice(doubleprice){
this.price=price;
}
publicdoublegetPrice(){
returnthis.price;
}
publicvoidsetReserves(intreserves){
this.reserves=reserves;
}
publicintgetReserves(){
returnthis.reserves;
}
publicvoidsetBirthdate(Stringbirthdate){
this.birthdate=birthdate;
}
publicStringgetBirthdate(){
returnthis.birthdate;
}
publicvoidsetQualitydate(intqualitydate){
this.qualitydate=qualitydate;
}
publicintgetQualitydate(){
returnthis.qualitydate;
}
publicvoidsetIndex(intindex){
this.index=index;
}
publicintgetIndex(){
returnthis.index;
}
}
classMeasure{
privateArrayListaa=null;
Measure(){
aa=newArrayList();
}
Scannerin=newScanner(System.in);
Stringmsg="\t食品名\t编号\t价格\t储量\t生产日期\t\t保质期";
Stringlsp="------恰恰食品管理系统---------";
publicvoidprint(Foodfood){
System.out.println(lsp);
System.out.println(msg);
//System.out.println(foodarr[i]);
System.out.println("\t"+food.getName()+"\t"+food.getBianhao()+"\t"+food.getPrice()+"\t"+food.getReserves()+"\t"+food.getBirthdate()+"\t\t"+food.getQualitydate());
}
publicvoidaddFood(Stringname,Stringbianhao){
//System.out.println("请输入要添加的食品名");
Foodfood=newFood();
aa.add(food);
food.setName(name);
//System.out.println("请输入食品"+food.getName()+"编号");
food.setBianhao(bianhao);
/*System.out.println(lsp);
System.out.println(msg);
System.out.println("\t"+food.getName()+"\t"+food.getBianhao()+"\t"+food.getPrice()+"\t"+food.getReserves()+"\t"+food.getBirthdate()+"\t\t"+food.getQualitydate());
*/
print(food);
}
publicvoidselectFoodbybianhao(Stringbianhao){//根据编号查找食品
inti;
for(i=0;i Foodfood=(Food)aa.get(i);
if(food.getBianhao().equals(bianhao)){
print(food);
break;
}
}
if(i==aa.size()){
System.out.println("对不起,无此食品");
}
}
publicvoidselectFoodbyname(Stringname){//根据食品名查找食品
inti;
for(i=0;i Foodfood=(Food)aa.get(i);
if(food.getName().equals(name)){
print(food);
break;
}
}
if(i==aa.size()){
System.out.println("对不起,无此食品");
}
}
publicvoiddelectFoodbybianhao(Stringbianhao){
inti;
if(aa.size()==0){
System.out.println("对不起仓库已无食品");
}
for(i=0;i Foodfood=(Food)aa.get(i);
if(food.getBianhao().equals(bianhao)){
aa.remove(i);
System.out.println("删除食品成功");
print(food);
break;
}
}
if(i==aa.size()&&aa.size()!
=0){
System.out.println("没有该类食品");
}
}
publicvoidupdateFood(Stringname,doubleprice,intreserves,Stringbirthdate,intqualitydate){
inti;
for(i=0;i Foodfood=(Food)aa.get(i);
if(food.getName().equals(name)){
food.setPrice(price);
food.setReserves(reserves);
food.setBirthdate(birthdate);
food.setQualitydate(qualitydate);
aa.add(food);
print(food);
break;
}
}
if(i==aa.size()){
System.out.println("对不起,无此食品");
}
}
}
publicclassTest7{
publicstaticvoidmain(String[]args){
Scannerin=newScanner(System.in);
//ArrayListshow=newArrayList();
Measuremeasure=newMeasure();
//BufferedReaderse=newBufferedReader(newInputStreamReader(System.in));
while(true){
System.out.println("恰恰食品管理系统");
System.out.println("请选择以下你要执行的功能");
System.out.println("添加一种食品请按1");
System.out.println("查找一种食品请按2");
System.out.println("删除一个食品请按3");
System.out.println("更新一种食品信息请按4");
System.out.println("退出请按99");
System.out.println("请输入要执行的功能的代码");
Stringaction=in.next();
if(action.equals("1")){
System.out.println("请输入食品名");
Stringname=in.next();
System.out.println("请输入食品编号");
Stringbianhao=in.next();
measure.addFood(name,bianhao);
}elseif(action.equals("2")){
System.out.println("正在执行查询食品操作");
System.out.println("请输入食品名");
Stringbianhao=in.next();
measure.selectFoodbybianhao(bianhao);
}elseif(action.equals("3")){
System.out.println("正在执行删除食品操作");
System.out.println("请输入食品编号");
Stringbianhao=in.next();
measure.delectFoodbybianhao(bianhao);
}elseif(action.equals("4")){
System.out.println("正在执行更新食品信息操作");
System.out.println("请输入要更新信息的食品名");
Stringname=in.next();
System.out.println("请输入"+name+"的价格");
double