java实现肯德基收银系统
程序员文章站
2024-02-24 13:11:23
参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用c++或java或python结合设计模式(2种以上)至少实现系统的以下功能:
1.正常餐品结算和找零。
2.基...
参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用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); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: java导出Excel通用方法实例
下一篇: 深入理解hibernate的三种状态