java实现肯德基收银系统
参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++或Java或Python结合设计模式(2种以上)至少实现系统的以下功能:
1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠券购买餐品结算和找零。
4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
5.模拟打印小票的功能(写到文件中)。
小票信息保存
classprint{ Strings="";//存订单信息 }
食物工厂
interfaceFoodFactory{ publicHamburgercreateHamburger(prints,intkind,intnum);//生产汉堡包 publicDrinkcreateDrink(prints,intkind,intnum);//生产饮品 publicChickencreateChicken(prints,intkind,intnum);//生产鸡肉类 publicSweetmeatscreateSweetmeats(prints,intkind,intnum);//生产甜品 publicSnackcreateSnack(prints,intkind,intnum);//生产小吃 publicFrenchFriescreateFrenchFries(prints,intkind,intnum);//生产薯条 publicSetMealcreateSetMeal(prints,intkind,intnum);//生产套餐 }
具体食物工厂
interfaceHamburger{ publicdoubleprice(intnum); } interfaceDrink{ publicdoubleprice(intnum); } interfaceChicken{ publicdoubleprice(intnum); } interfaceSweetmeats{ publicdoubleprice(intnum); } interfaceSnack{ publicdoubleprice(intnum); } interfaceFrenchFries{ publicdoubleprice(intnum); } interfaceSetMeal{ publicdoubleprice(intnum); }
具体食物
//汉堡 //奥尔良烤堡 classHamburger_1implementsHamburger{ publicdoubleprice(intnum) { System.out.println("奥尔良烤堡"+""+"数量:"+num+""+"合计:"+(num*8)); returnnum*8;//返回价格 } } //香辣鸡腿堡 classHamburger_2implementsHamburger{ publicdoubleprice(intnum) { System.out.println("香辣鸡腿堡"+""+"数量:"+num+""+"合计:"+(num*9)); returnnum*9; } } //劲脆鸡腿堡 classHamburger_3implementsHamburger{ publicdoubleprice(intnum) { System.out.println("劲脆鸡腿堡"+""+"数量:"+num+""+"合计:"+(num*10)); returnnum*10; } } //饮品 //橙汁 classDrink_1implementsDrink{ publicdoubleprice(intnum) { System.out.println("橙汁"+""+"数量:"+num+""+"合计:"+(num*7)); returnnum*7;//返回价格 } } //百事可乐 classDrink_2implementsDrink{ publicdoubleprice(intnum) { System.out.println("百事可乐"+""+"数量:"+num+""+"合计:"+(num*8)); returnnum*8; } } //百威啤酒 classDrink_3implementsDrink{ publicdoubleprice(intnum) { System.out.println("百威啤酒"+""+"数量:"+num+""+"合计:"+(num*9)); returnnum*9; } } //鸡肉类 //老北京鸡肉卷 classChicken_1implementsChicken{ publicdoubleprice(intnum) { System.out.println("老北京鸡肉卷"+""+"数量:"+num+""+"合计:"+(num*9)); returnnum*9;//返回价格 } } //香辣鸡翅 classChicken_2implementsChicken{ publicdoubleprice(intnum) { System.out.println("香辣鸡翅"+""+"数量:"+num+""+"合计:"+(num*13)); returnnum*13; } } //鸡排 classChicken_3implementsChicken{ publicdoubleprice(intnum) { System.out.println("鸡排"+""+"数量:"+num+""+"合计:"+(num*10)); returnnum*10; } } //甜品 //原味圣代 classSweetmeats_1implementsSweetmeats{ publicdoubleprice(intnum) { System.out.println("原味圣代"+""+"数量:"+num+""+"合计:"+(num*9)); returnnum*9;//返回价格 } } //葡式蛋挞 classSweetmeats_2implementsSweetmeats{ publicdoubleprice(intnum) { System.out.println("葡式蛋挞"+""+"数量:"+num+""+"合计:"+(num*12)); returnnum*12; } } //巧克力味华夫 classSweetmeats_3implementsSweetmeats{ publicdoubleprice(intnum) { System.out.println("巧克力味华夫"+""+"数量:"+num+""+"合计:"+(num*10)); returnnum*10; } } //小吃 //蔬菜沙拉 classSnack_1implementsSnack{ publicdoubleprice(intnum) { System.out.println("蔬菜沙拉"+""+"数量:"+num+""+"合计:"+(num*10)); returnnum*10;//返回价格 } } //醇香土豆泥 classSnack_2implementsSnack{ publicdoubleprice(intnum) { System.out.println("醇香土豆泥"+""+"数量:"+num+""+"合计:"+(num*11)); returnnum*11; } } //香甜粟米棒 classSnack_3implementsSnack{ publicdoubleprice(intnum) { System.out.println("香甜粟米棒"+""+"数量:"+num+""+"合计:"+(num*6)); returnnum*6; } } //薯条 //波纹霸王薯条 classFrenchFries_1implementsFrenchFries{ publicdoubleprice(intnum) { System.out.println("波纹霸王薯条"+""+"数量:"+num+""+"合计:"+(num*12)); returnnum*12;//返回价格 } } //套餐 //套餐1 classSetMeal_1implementsSetMeal{ publicdoubleprice(intnum){ System.out.println("香辣鸡翅+百事可乐"+""+"数量:"+num+""+"合计:"+(num*17)); returnnum*17; } } //套餐2 classSetMeal_2implementsSetMeal{ publicdoubleprice(intnum){ System.out.println("劲脆鸡腿堡+橙汁"+""+"数量:"+num+""+"合计:"+(num*15)); returnnum*15; } } //套餐3 classSetMeal_3implementsSetMeal{ publicdoubleprice(intnum){ System.out.println("香辣鸡腿堡+百威啤酒+波纹霸王薯条"+""+"数量:"+num+""+"合计:"+(num*25)); returnnum*25; } }
生产具体食物
//生产具体食物 classcreateFoodimplementsFoodFactory{ printp=newprint(); publicHamburgercreateHamburger(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"奥尔良汉堡单价:"+"8"+"数量:"+num+"合计:"+(num*8);//将信息保存至s中 returnnewHamburger_1();} elseif(kind==2){ s.s=s.s+"\n"+"香辣鸡腿堡单价:"+"9"+"数量:"+num+"合计:"+(num*9); returnnewHamburger_2();} elseif(kind==3){ s.s=s.s+"\n"+"劲脆鸡腿堡单价:"+"10"+"数量:"+num+"合计:"+(num*10); returnnewHamburger_3();} elsereturnnull; } publicDrinkcreateDrink(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"橙汁单价:"+"7"+"数量:"+num+"合计:"+(num*7);//将信息保存至s中 returnnewDrink_1();} elseif(kind==2){ s.s=s.s+"\n"+"百事可乐单价:"+"8"+"数量:"+num+"合计:"+(num*8); returnnewDrink_2();} elseif(kind==3){ s.s=s.s+"\n"+"百威啤酒单价:"+"9"+"数量:"+num+"合计:"+(num*9); returnnewDrink_3();} elsereturnnull; } publicChickencreateChicken(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"老北京鸡肉卷单价:"+"9"+"数量"+num+"合计:"+(num*9);//将信息保存至s中 returnnewChicken_1();} elseif(kind==2){ s.s=s.s+"\n"+"香辣鸡翅单价:"+"13"+"数量"+num+"合计:"+(num*13); returnnewChicken_2();} elseif(kind==3){ s.s=s.s+"\n"+"鸡排单价:"+"10"+"数量"+num+"合计:"+(num*10); returnnewChicken_3();} elsereturnnull; } publicSweetmeatscreateSweetmeats(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"原味圣代单价:"+"9"+"数量"+num+"合计:"+(num*9);//将信息保存至s中 returnnewSweetmeats_1();} elseif(kind==2){ s.s=s.s+"\n"+"葡式蛋挞单价:"+"12"+"数量"+num+"合计:"+(num*12); returnnewSweetmeats_2();} elseif(kind==3){ s.s=s.s+"\n"+"巧克力味华夫单价:"+"10"+"数量"+num+"合计:"+(num*10); returnnewSweetmeats_3();} elsereturnnull; } publicSnackcreateSnack(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"蔬菜沙拉单价:"+"10"+"数量"+num+"合计:"+(num*10);//将信息保存至s中 returnnewSnack_1();} elseif(kind==2){ s.s=s.s+"\n"+"醇香土豆泥单价:"+"11"+"数量"+num+"合计:"+(num*11); returnnewSnack_2();} elseif(kind==3){ s.s=s.s+"\n"+"香甜粟米棒单价:"+"6"+"数量"+num+"合计:"+(num*6); returnnewSnack_3();} elsereturnnull; } publicFrenchFriescreateFrenchFries(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"波纹霸王薯条单价:"+"12"+"数量"+num+"合计:"+(num*12);//将信息保存至s中 returnnewFrenchFries_1();} elsereturnnull; } publicSetMealcreateSetMeal(prints,intkind,intnum){ if(kind==1){ s.s=s.s+"\n"+"套餐1单价:"+"17"+"数量"+num+"合计:"+(num*17);//将信息保存至s中 returnnewSetMeal_1();} elseif(kind==2){ s.s=s.s+"\n"+"套餐2单价:"+"15"+"数量"+num+"合计:"+(num*15); returnnewSetMeal_2();} elseif(kind==3){ s.s=s.s+"\n"+"套餐3单价:"+"25"+"数量"+num+"合计:"+(num*25); returnnewSetMeal_3();} elsereturnnull; } }
订购食物,返回价格
classPrice{ publicFoodFactorycreate; //构造方法将抽象工厂传入 publicPrice(FoodFactorycreate){ this.create=create; } publicdoubleorderHamburger(prints,intkind,intnum){ Hamburgerhamburger=create.createHamburger(s,kind,num); returnhamburger.price(num); } publicdoubleorderDrink(prints,intkind,intnum){ Drinkdrink=create.createDrink(s,kind,num); returndrink.price(num); } publicdoubleorderChicken(prints,intkind,intnum){ Chickenchicken=create.createChicken(s,kind,num); returnchicken.price(num); } publicdoubleorderSweetmeats(prints,intkind,intnum){ Sweetmeatssweetmeats=create.createSweetmeats(s,kind,num); returnsweetmeats.price(num); } publicdoubleorderSnack(prints,intkind,intnum){ Snacksnack=create.createSnack(s,kind,num); returnsnack.price(num); } publicdoubleorderFrenchFries(prints,intkind,intnum){ FrenchFriesfrenchFries=create.createFrenchFries(s,kind,num); returnfrenchFries.price(num); } publicdoubleorderSetMeal(prints,intkind,intnum){ SetMealsetMeal=create.createSetMeal(s,kind,num); returnsetMeal.price(num); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。