KFC点餐系统

  1. 题目要求
    同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++/python/Java,结合设计模式(2种以上)至少实现系统的以下功能:

1.正常餐品结算和找零。

2.基本套餐结算和找零。

3.使用优惠劵购买餐品结算和找零。

4.可在一定时间段参与店内活动。

5.模拟打印小票的功能

  1. 部分代码
import java.util.Scanner;
//import KFC.baseStrategy;
//抽象工厂模式,套餐
//工厂模式:正常餐品
//策略模式 ,打折方式(1.不打折,2.优惠券-10元,3.活动期间全场85折,4.活动期间拥有优惠券,先减10元再*0.85)
/*
 1. 1.选择正常点餐还是选择套餐
 2. 2.支付选择正常支付还是折扣支付
 3. 3.看是不是活动时间,活动时间某样东西有优惠
 4. 4.打印小票(保存到文件中) 
 */
public class KfcMain {
	public static void main(String[] args) 
	{
		//文件输出采取[Console output redirected to file:D:\eclipse\note.txt]方式
		//文件保存在eclipse根目录下
		int num;
		int a,b,c,m = 0;
		System.out.println("**********欢迎使用肯德基点餐系统***********");
		System.out.println("**********请输入你需要的点餐方式***********");
		System.out.println("*******1.自主点餐********2.选择套餐******");
		@SuppressWarnings("resource")
		Scanner s=new Scanner(System.in);
		a=s.nextInt();
		/*
		 * 实体类对象
		 */
		hambuger h1=new hambuger();
		hambuger h2=new hambuger();
		chicken c1=new chicken();
		chicken c2=new chicken();
		french r1=new french();
		french r2=new french();
		breave b1=new breave();
		breave b2=new breave();
		float foodPrice=0f;
		float z=0;//自主点餐的原价
		//创建环境
		MemberStrategy strategy = new Activity();
        //创建价格
        Price price = new Price(strategy);
        MemberStrategy strategy1 = new baseStrategy();
        //创建环境
        Price price1 = new Price(strategy1);
		switch(a) {
		case 1:
			System.out.println("1.汉堡,2.鸡翅,3.薯条,4.饮品");
			b=s.nextInt();
			if(b==1) {
				System.out.println("请选择汉堡种类及数量:1.牛肉汉堡,2.香辣汉堡");
				m=s.nextInt();
				num=s.nextInt();
				switch(m) {
				case 1:
					h1.beelHanburm(num);
					h1.printMessage();
					float f1=price.quote(h1.totalPrice());
					System.out.println("活动期间打折价为:"+f1);
					float f11 = price1.quote(h1.totalPrice());
			        System.out.println("使用优惠券后价格为:"+f11);
			        float f12=price.quote(price1.quote(h1.totalPrice()));
			        System.out.println("优惠券+活动之后的价格为:"+f12);
					break;
				case 2:
					h2.xlHanburm(num);
					h2.printMessage();
					float f2=price.quote(h2.totalPrice());
					System.out.println("活动期间打折价为:"+f2);
					float f21 = price1.quote(h2.totalPrice());
			        System.out.println("使用优惠券后价格为:"+f21);
			        float f22=price.quote(price1.quote(h2.totalPrice()));
			        System.out.println("优惠券+活动之后的价格为:"+f22);
					break;
				}
				z=h1.totalPrice()+h2.totalPrice();
			}
			else if(b==2) {
				System.out.println("请选择鸡翅种类及数量:1.奥尔良鸡翅,2.香辣鸡翅");
				m=s.nextInt();
				num=s.nextInt();
				switch(m) {
				case 1:
					c1.aoChickenWings(num);
					c1.printMessage();
					float f3=price.quote(c1.totalPrice());
					System.out.println("活动期间打折价为:"+f3);
					float f31 = price1.quote(c1.totalPrice());
			        System.out.println("使用优惠券后价格为:"+f31);
			        float f32=price.quote(price1.quote(c1.totalPrice()));
			        System.out.println("优惠券+活动之后的价格为:"+f32);
					break;
				case 2:
					c2.laChickenWings(num);
					c2.printMessage();
					float f4=price.quote(c2.totalPrice());
					System.out.println("活动期间打折价为:"+f4);
					float f41 = price1.quote(c2.totalPrice());
			        System.out.println("使用优惠券后价格为:"+f41);
			        float f42=price.quote(price1.quote(c2.totalPrice()));
			        System.out.println("优惠券+活动之后的价格为:"+f42);
					break;
				}
				z=c1.totalPrice()+c2.totalPrice();
			}
				else if(b==3) {
					System.out.println("请选择薯条种类及数量:1.小份,2.大份");
					m=s.nextInt();
					num=s.nextInt();
					switch(m) {
					case 1:
						r1.sFrenchFries(num);
						r1.printMessage();
						float f5=price.quote(r1.totalPrice());
						System.out.println("活动期间打折价为:"+f5);
						float f51 = price1.quote(r1.totalPrice());
				        System.out.println("使用优惠券后价格为:"+f51);
				        float f52=price.quote(price1.quote(r1.totalPrice()));
				        System.out.println("优惠券+活动之后的价格为:"+f52);
						break;
					case 2:
						r2.lFrenchFries(num);
						r2.printMessage();
						float f6=price.quote(r2.totalPrice());
						System.out.println("活动期间打折价为:"+f6);
						float f61 = price1.quote(r2.totalPrice());
				        System.out.println("使用优惠券后价格为:"+f61);
				        float f62=price.quote(price1.quote(r2.totalPrice()));
				        System.out.println("优惠券+活动之后的价格为:"+f62);
						break;
					}
					z=r1.totalPrice()+r2.totalPrice();
			}
				else if(b==4) {
					System.out.println("请选择饮品种类及数量:1.可乐,2.橙汁");
					m=s.nextInt();
					num=s.nextInt();
					switch(m) {
					case 1:
						b1.cola(num);
						b1.printMessage();
						float f7=price.quote(b1.totalPrice());
						System.out.println("活动期间打折价为:"+f7);
						float f71 = price1.quote(b1.totalPrice());
				        System.out.println("使用优惠券后价格为:"+f71);
				        float f72=price.quote(price1.quote(b1.totalPrice()));
				        System.out.println("优惠券+活动之后的价格为:"+f72);
						break;
					case 2:
						b2.Orange(num);
						b2.printMessage();
						float f8=price.quote(b2.totalPrice());
						System.out.println("活动期间打折价为:"+f8);
						float f81 = price1.quote(b2.totalPrice());
				        System.out.println("使用优惠券后价格为:"+f81);
				        float f82=price.quote(price1.quote(b2.totalPrice()));
				        System.out.println("优惠券+活动之后的价格为:"+f82);
						break;
					}
					z=b1.totalPrice()+b2.totalPrice();//饮品总价格
			}
			break;
		case 2:
			//套餐模式
			//抽象工场模式
			System.out.println("基本套餐为:");
			IKFCFactory kfcFactory=new KfcFactory();
			Hamburg hamburg=kfcFactory.createHamburg(1);
			hamburg.printMessage();
		    ChickenWings wings=kfcFactory.createChickenWings(1);
			wings.printMessage();
			FrenchFires french=kfcFactory.createFrenchFries(1);
			french.printMessage();
			Drink drink=kfcFactory.createBeverage(1);
			drink.printMessage();
			//套餐总价
			foodPrice=hamburg.price+wings.price+french.price+drink.price;
	        //计算价格
	        float quote = price.quote(foodPrice);
	        System.out.println("活动期间打折价为:"+quote);
	        float quote1 = price1.quote(foodPrice);
	        System.out.println("使用优惠券后价格为:"+quote1);
	        float quote2=price.quote(quote1);
	        System.out.println("优惠券+活动之后的价格为:"+quote2);
			break;
		}
		System.out.println("*************请选择付款方式*************");
		System.out.println("1.正常支付,2.优惠券支付 3.活动期间折扣,4.活动期间使用优惠券");
		c=s.nextInt();//获取用户选择
		float g=0;
		float t=0;
		switch(c)
		{
		case 1:
			if(m==1) {
				System.out.println("总计"+z);
				System.out.println("请付款:");
				g=s.nextFloat();//获取付款钱数
				t=g-z;
			}
				
			else
			{
				System.out.println("总计"+foodPrice);
				System.out.println("请付款:");
				g=s.nextFloat();//获取付款钱数
			    t=g-foodPrice;
			}
			if(t>0)
			{
				System.out.println("找零:"+t);
				System.out.println("请收好您的票据,欢迎下次光临");
			}
			else
			{
				System.out.println("付款数不足,请重新付款");
				while(t>=0) {
					System.out.println("付款成功,请收好您的票据,欢迎下次光临");
				}
			}
			break;
		case 2:
			if (m==1) {//当选择自主选餐时
				System.out.println("总计"+price1.quote(z));
				System.out.println("请付款:");
			    g=s.nextFloat();
				t=g-price1.quote(z);//找零方式
				}
			else{//当选择套餐模式时
				System.out.println("总计"+price1.quote(foodPrice));
				System.out.println("请付款:");
			    g=s.nextFloat();
			   t=g-price1.quote(foodPrice);//找零方式
			}
			if(t>0)
			{
				System.out.println("找零:"+t);
				System.out.println("请收好您的票据,欢迎下次光临");
			}
			else
			{
				System.out.println("付款数不足,请重新付款");
				while(t>=0) {
					System.out.println("付款成功,请收好您的票据,欢迎下次光临");
				}
			}
			break;
		case 3:
			if(m==1) {
				System.out.println("总计"+price.quote(z));
				System.out.println("请付款:");
			    g=s.nextFloat();
				t=g-price.quote(z);//找零方式
			}
			else
			{
				System.out.println("总计"+price.quote(foodPrice));
				System.out.println("请付款:");
			    g=s.nextFloat();
			    t=g-price.quote(foodPrice);
			}
			if(t>0)
			{
				System.out.println("找零:"+t);
				System.out.println("请收好您的票据,欢迎下次光临");
			}
			else
			{
				System.out.println("付款数不足,请重新付款");
				while(t>=0) {
					System.out.println("付款成功,请收好您的票据,欢迎下次光临");
				}
			}
			break;
		case 4:
			if(m==1) {
				System.out.println("总计"+price.quote(price1.quote(z)));
				System.out.println("请付款:");
			    g=s.nextFloat();
				t=g-price.quote(price1.quote(z));//找零方式
			}
			else
			{
				System.out.println("总计"+price.quote(price1.quote(foodPrice)));
				System.out.println("请付款:");
			    g=s.nextFloat();
			    t=g-price.quote(price1.quote(foodPrice));
			}
			if(t>0)
			{
				System.out.println("找零:"+t);
				System.out.println("请收好您的票据,欢迎下次光临");
			}
			else
			{
				System.out.println("付款数不足,请重新付款");
				while(t>=0) {
					System.out.println("付款成功,请收好您的票据,欢迎下次光临");
				}
			}
			break;
		} 
	}
	
	}
  1. 截图
    在这里插入图片描述
    在这里插入图片描述
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值