您好,登錄后才能下訂單哦!
參考肯德基官網的信息模擬肯德基快餐店的收銀系統,合理使用C++或Java或Python結合設計模式(2種以上)至少實現系統的以下功能:
1.正常餐品結算和找零。
2.基本套餐結算和找零。
3.使用優惠券購買餐品結算和找零。
4.可在一定時間段參與店內活動(自行設計或參考官網信息)。
5.模擬打印小票的功能(寫到文件中)。
小票信息保存
class print{ String s=""; //存訂單信息 }
食物工廠
interface FoodFactory{ public Hamburger createHamburger(print s,int kind,int num); //生產漢堡包 public Drink createDrink(print s,int kind,int num); //生產飲品 public Chicken createChicken(print s,int kind,int num); //生產雞肉類 public Sweetmeats createSweetmeats(print s,int kind,int num); //生產甜品 public Snack createSnack(print s,int kind,int num); //生產小吃 public FrenchFries createFrenchFries(print s,int kind,int num); //生產薯條 public SetMeal createSetMeal(print s,int kind,int num); //生產套餐 }
具體食物工廠
interface Hamburger{ public double price(int num); } interface Drink{ public double price(int num); } interface Chicken{ public double price(int num); } interface Sweetmeats{ public double price(int num); } interface Snack{ public double price(int num); } interface FrenchFries{ public double price(int num); } interface SetMeal{ public double price(int num); }
具體食物
//漢堡 //奧爾良烤堡 class Hamburger_1 implements Hamburger{ public double price(int num) { System.out.println("奧爾良烤堡"+" "+" 數量:"+num+" "+"合計:"+(num*8)); return num*8; //返回價格 } } //香辣雞腿堡 class Hamburger_2 implements Hamburger{ public double price(int num) { System.out.println("香辣雞腿堡"+" "+" 數量:"+num+" "+"合計:"+(num*9)); return num*9; } } //勁脆雞腿堡 class Hamburger_3 implements Hamburger{ public double price(int num) { System.out.println("勁脆雞腿堡"+" "+" 數量:"+num+" "+"合計:"+(num*10)); return num*10; } } //飲品 //橙汁 class Drink_1 implements Drink{ public double price(int num) { System.out.println("橙汁"+" "+" 數量:"+num+" "+"合計:"+(num*7)); return num*7; //返回價格 } } //百事可樂 class Drink_2 implements Drink{ public double price(int num) { System.out.println("百事可樂"+" "+" 數量:"+num+" "+"合計:"+(num*8)); return num*8; } } //百威啤酒 class Drink_3 implements Drink{ public double price(int num) { System.out.println("百威啤酒"+" "+" 數量:"+num+" "+"合計:"+(num*9)); return num*9; } } //雞肉類 //老北京雞肉卷 class Chicken_1 implements Chicken{ public double price(int num) { System.out.println("老北京雞肉卷"+" "+"數量:"+num+" "+"合計:"+(num*9)); return num*9; //返回價格 } } //香辣雞翅 class Chicken_2 implements Chicken{ public double price(int num) { System.out.println("香辣雞翅"+" "+"數量:"+num+" "+"合計:"+(num*13)); return num*13; } } //雞排 class Chicken_3 implements Chicken{ public double price(int num) { System.out.println("雞排"+" "+"數量:"+num+" "+"合計:"+(num*10)); return num*10; } } //甜品 //原味圣代 class Sweetmeats_1 implements Sweetmeats{ public double price(int num) { System.out.println("原味圣代"+" "+"數量:"+num+" "+"合計:"+(num*9)); return num*9; //返回價格 } } //葡式蛋撻 class Sweetmeats_2 implements Sweetmeats{ public double price(int num) { System.out.println("葡式蛋撻"+" "+"數量:"+num+" "+"合計:"+(num*12)); return num*12; } } //巧克力味華夫 class Sweetmeats_3 implements Sweetmeats{ public double price(int num) { System.out.println("巧克力味華夫"+" "+"數量:"+num+" "+"合計:"+(num*10)); return num*10; } } //小吃 //蔬菜沙拉 class Snack_1 implements Snack{ public double price(int num) { System.out.println("蔬菜沙拉"+" "+"數量:"+num+" "+"合計:"+(num*10)); return num*10; //返回價格 } } //醇香土豆泥 class Snack_2 implements Snack{ public double price(int num) { System.out.println("醇香土豆泥"+" "+"數量:"+num+" "+"合計:"+(num*11)); return num*11; } } //香甜粟米棒 class Snack_3 implements Snack{ public double price(int num) { System.out.println("香甜粟米棒"+" "+"數量:"+num+" "+"合計:"+(num*6)); return num*6; } } //薯條 //波紋霸王薯條 class FrenchFries_1 implements FrenchFries{ public double price(int num) { System.out.println("波紋霸王薯條"+" "+"數量:"+num+" "+"合計:"+(num*12)); return num*12; //返回價格 } } //套餐 //套餐1 class SetMeal_1 implements SetMeal{ public double price(int num) { System.out.println("香辣雞翅+百事可樂"+" "+"數量:"+num+" "+"合計:"+(num*17)); return num*17; } } //套餐2 class SetMeal_2 implements SetMeal{ public double price(int num) { System.out.println("勁脆雞腿堡+橙汁"+" "+"數量:"+num+" "+"合計:"+(num*15)); return num*15; } } //套餐3 class SetMeal_3 implements SetMeal{ public double price(int num) { System.out.println("香辣雞腿堡+百威啤酒+波紋霸王薯條"+" "+"數量:"+num+" "+"合計:"+(num*25)); return num*25; } }
生產具體食物
//生產具體食物 class createFood implements FoodFactory{ print p=new print(); public Hamburger createHamburger(print s,int kind,int num) { if(kind==1){ s.s=s.s+"\n"+"奧爾良漢堡 單價:"+"8"+" 數量:"+num+" 合計:"+(num*8); //將信息保存至s中 return new Hamburger_1();} else if(kind==2) { s.s=s.s+"\n"+"香辣雞腿堡 單價:"+"9"+" 數量:"+num+" 合計:"+(num*9); return new Hamburger_2();} else if(kind==3) { s.s=s.s+"\n"+"勁脆雞腿堡 單價:"+"10"+" 數量:"+num+" 合計:"+(num*10); return new Hamburger_3();} else return null; } public Drink createDrink(print s,int kind,int num) { if(kind==1) { s.s=s.s+"\n"+"橙汁 單價:"+"7"+" 數量:"+num+" 合計:"+(num*7); //將信息保存至s中 return new Drink_1();} else if(kind==2) { s.s=s.s+"\n"+"百事可樂 單價:"+"8"+" 數量:"+num+" 合計:"+(num*8); return new Drink_2();} else if(kind==3) { s.s=s.s+"\n"+"百威啤酒 單價:"+"9"+" 數量:"+num+" 合計:"+(num*9); return new Drink_3();} else return null; } public Chicken createChicken(print s,int kind,int num) { if(kind==1) { s.s=s.s+"\n"+"老北京雞肉卷 單價:"+"9"+" 數量"+num+" 合計:"+(num*9); //將信息保存至s中 return new Chicken_1();} else if(kind==2) { s.s=s.s+"\n"+"香辣雞翅 單價:"+"13"+" 數量"+num+" 合計:"+(num*13); return new Chicken_2();} else if(kind==3) { s.s=s.s+"\n"+"雞排 單價:"+"10"+" 數量"+num+" 合計:"+(num*10); return new Chicken_3();} else return null; } public Sweetmeats createSweetmeats(print s,int kind,int num) { if(kind==1) { s.s=s.s+"\n"+"原味圣代 單價:"+"9"+" 數量"+num+" 合計:"+(num*9); //將信息保存至s中 return new Sweetmeats_1();} else if(kind==2) { s.s=s.s+"\n"+"葡式蛋撻 單價:"+"12"+" 數量"+num+" 合計:"+(num*12); return new Sweetmeats_2();} else if(kind==3) { s.s=s.s+"\n"+"巧克力味華夫 單價:"+"10"+" 數量"+num+" 合計:"+(num*10); return new Sweetmeats_3();} else return null; } public Snack createSnack(print s,int kind,int num) { if(kind==1) { s.s=s.s+"\n"+"蔬菜沙拉 單價:"+"10"+" 數量"+num+" 合計:"+(num*10); //將信息保存至s中 return new Snack_1();} else if(kind==2) { s.s=s.s+"\n"+"醇香土豆泥 單價:"+"11"+" 數量"+num+" 合計:"+(num*11); return new Snack_2();} else if(kind==3) { s.s=s.s+"\n"+"香甜粟米棒 單價:"+"6"+" 數量"+num+" 合計:"+(num*6); return new Snack_3();} else return null; } public FrenchFries createFrenchFries(print s,int kind,int num){ if(kind==1) { s.s=s.s+"\n"+"波紋霸王薯條 單價:"+"12"+" 數量"+num+" 合計:"+(num*12); //將信息保存至s中 return new FrenchFries_1();} else return null; } public SetMeal createSetMeal(print s,int kind, int num) { if(kind==1) { s.s=s.s+"\n"+"套餐1 單價:"+"17"+" 數量"+num+" 合計:"+(num*17); //將信息保存至s中 return new SetMeal_1();} else if(kind==2) { s.s=s.s+"\n"+"套餐2 單價:"+"15"+" 數量"+num+" 合計:"+(num*15); return new SetMeal_2();} else if(kind==3) { s.s=s.s+"\n"+"套餐3 單價:"+"25"+" 數量"+num+" 合計:"+(num*25); return new SetMeal_3();} else return null; } }
訂購食物,返回價格
class Price{ public FoodFactory create; //構造方法將抽象工廠傳入 public Price(FoodFactory create) { this.create=create; } public double orderHamburger(print s,int kind,int num) { Hamburger hamburger=create.createHamburger(s,kind, num); return hamburger.price(num); } public double orderDrink(print s,int kind,int num) { Drink drink=create.createDrink(s,kind, num); return drink.price(num); } public double orderChicken(print s,int kind,int num) { Chicken chicken=create.createChicken(s,kind, num); return chicken.price(num); } public double orderSweetmeats(print s,int kind,int num) { Sweetmeats sweetmeats=create.createSweetmeats(s,kind, num); return sweetmeats.price(num); } public double orderSnack(print s,int kind,int num) { Snack snack=create.createSnack(s,kind, num); return snack.price(num); } public double orderFrenchFries(print s,int kind,int num) { FrenchFries frenchFries=create.createFrenchFries(s,kind, num); return frenchFries.price(num); } public double orderSetMeal(print s,int kind,int num) { SetMeal setMeal=create.createSetMeal(s,kind, num); return setMeal.price(num); } }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。