模拟肯德基快餐店收银系统

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

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

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

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

4.可在一定时间段参与店内活动(自行设计或参考官网信息)。

5.模拟打印小票的功能(写到文件中)。

用时2周。

基本要求:

  1. 程序设计风格良好,控制台界面友好,最多两人一组完成任务。
  2. 实现功能测试代码,确保程序的健壮性。
  3. 画出使用的设计模式图。

提高要求:

  1. 实现可视化界面。
  2. 实现会员储值卡功能,完成储值卡消费。
  3. 实现当天营业额和餐品销量计算和统计,用数据库记录。

附:

肯德基点餐(收银)系统特点:

  1. 可单点,包括炸鸡、汉堡、饮料、薯条等。
  2. 可点套餐,套餐分为三类:早餐、正餐、夜宵,且套餐会标明具体节省几元。
  3. 套餐中:早餐和正餐含有满xx元可1元购餐活动,夜宵含有满xx元可半价购餐活动。(选做)
  4. 部分商品含有会员价。

代码示例:

工厂类接口:

public interface Factory {
    Food createFood();
}
public interface MealFactory {
    Meal creatMeal();
}

产品类接口:

public interface Food {
    boolean hasOnSale();
    double getPrice();
    double getSalePrice();
    void setCount(int count);
    int getCount();
}
public interface Meal {
    double getPrize();
    void setCount(int count);
    int getCount();
}

工厂类:

class HamburgerFactory implements Factory{
    @Override
    public Food createFood() {
        return new Hamburger();
    }
}

class ChickenFactory implements Factory{
    @Override
    public Food createFood() {
        return new Chicken();
    }
}

class FriesFactory implements Factory{
    @Override
    public Food createFood() {
        return new Fries();
    }
}

class DrinkFactory implements Factory{
    @Override
    public Food createFood() {
        return new Drink();
    }
}
class ChildFactory implements MealFactory{
    @Override
    public Meal creatMeal() {
        return new Child();
    }
}

class SingleFactory implements MealFactory{
    @Override
    public Meal creatMeal() {
        return new Single();
    }
}

class CoupleFactory implements MealFactory{
    @Override
    public Meal creatMeal() {
        return new Couple();
    }
}

class HomeFactory implements MealFactory{
    @Override
    public Meal creatMeal() {
        return new Home();
    }
}

产品类:

class Hamburger implements Food{
    private double price=18;
    private double sale=0.9;
    private int count=0;

    @Override
    public boolean hasOnSale() {
        return true;
    }

    @Override
    public double getPrice() {
        return this.price;
    }

    @Override
    public double getSalePrice(){
        return this.price*this.sale;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}

class Chicken implements Food{
    private double price=12;
    private double sale=0.95;
    private int count=0;

    @Override
    public boolean hasOnSale() {
        return true;
    }

    @Override
    public double getPrice() {
        return this.price;
    }

    @Override
    public double getSalePrice(){
        return this.price*this.sale;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}

class Fries implements Food{
    private double price=11;
    private double sale=1;
    private int count=0;

    @Override
    public boolean hasOnSale() {
        return false;
    }

    @Override
    public double getPrice() {
        return this.price;
    }

    @Override
    public double getSalePrice() {
        return this.price;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}

class Drink implements Food{
    private double price=10;
    private double sale=1;
    private int count=0;

    @Override
    public boolean hasOnSale() {
        return false;
    }

    @Override
    public double getPrice() {
        return this.price;
    }

    @Override
    public double getSalePrice() {
        return this.price;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
import java.util.ArrayList;

class Child implements Meal{
    private  ArrayList<Food> m=new ArrayList<Food>();
    private  double sale=0.8;
    private int count=0;

    public Child(){
        HamburgerFactory hf=new HamburgerFactory();
        FriesFactory ff=new FriesFactory();
        DrinkFactory df=new DrinkFactory();
        m.add(hf.createFood());
        m.add(ff.createFood());
        m.add(df.createFood());
    }

    @Override
    public double getPrize() {
        double num=0;
        for (Food i:m){
            num+=i.getPrice();
        }
        return num*this.sale;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}

class Single implements Meal{
    private  ArrayList<Food> m=new ArrayList<Food>();
    private  double sale=0.85;
    private int count=0;

    public Single(){
        HamburgerFactory hf=new HamburgerFactory();
        ChickenFactory cf=new ChickenFactory();
        DrinkFactory df=new DrinkFactory();
        m.add(hf.createFood());
        m.add(cf.createFood());
        m.add(df.createFood());
    }

    @Override
    public double getPrize() {
        double num=0;
        for (Food i:m){
            num+=i.getPrice();
        }
        return num*this.sale;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}

class Couple implements Meal{
    private  ArrayList<Food> m=new ArrayList<Food>();
    private  double sale=0.75;
    private int count=0;

    public Couple(){
        HamburgerFactory hf=new HamburgerFactory();
        ChickenFactory cf=new ChickenFactory();
        FriesFactory ff=new FriesFactory();
        DrinkFactory df=new DrinkFactory();
        m.add(hf.createFood());
        m.add(hf.createFood());
        m.add(cf.createFood());
        m.add(ff.createFood());
        m.add(df.createFood());
        m.add(df.createFood());
    }

    @Override
    public double getPrize() {
        double num=0;
        for (Food i:m){
            num+=i.getPrice();
        }
        return num*this.sale;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}

class Home implements Meal{
    private  ArrayList<Food> m=new ArrayList<Food>();
    private  double sale=0.7;
    private int count=0;

    public Home(){
        HamburgerFactory hf=new HamburgerFactory();
        ChickenFactory cf=new ChickenFactory();
        FriesFactory ff=new FriesFactory();
        DrinkFactory df=new DrinkFactory();
        m.add(hf.createFood());
        m.add(hf.createFood());
        m.add(cf.createFood());
        m.add(cf.createFood());
        m.add(ff.createFood());
        m.add(ff.createFood());
        m.add(df.createFood());
        m.add(df.createFood());
    }

    @Override
    public double getPrize() {
        double num=0;
        for (Food i:m){
            num+=i.getPrice();
        }
        return num*this.sale;
    }

    @Override
    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public int getCount() {
        return count;
    }
}
客户端:
import java.io.*;
import java.util.Scanner;

public class User {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("欢迎您来到KFC用餐,请点餐。");
        System.out.println("请选择点餐方式:1:单点,2:套餐,3:结束点餐。");
        String s=null;
        int i=0;
        Food hamburger=new HamburgerFactory().createFood();
        Food chicken=new ChickenFactory().createFood();
        Food fries=new FriesFactory().createFood();
        Food drink=new DrinkFactory().createFood();
        Meal child=new ChildFactory().creatMeal();
        Meal single=new SingleFactory().creatMeal();
        Meal couple=new CoupleFactory().creatMeal();
        Meal home=new HomeFactory().creatMeal();
        while (scanner.hasNextInt()){
            i=scanner.nextInt();
            if (i==1){
                System.out.println("请选择餐品种类:1:汉堡,2:炸鸡,3,:薯条,4:饮料,5:重新选择点餐方式。");
                while (scanner.hasNextInt()){
                    i=scanner.nextInt();
                    if (i==1){
                        System.out.println("请输入数量。");
                        hamburger.setCount(scanner.nextInt());
                    }
                    else if (i==2){
                        System.out.println("请输入数量。");
                        chicken.setCount(scanner.nextInt());
                    }
                    else if (i==3){
                        System.out.println("请输入数量。");
                        fries.setCount(scanner.nextInt());
                    }
                    else if (i==4){
                        System.out.println("请输入数量。");
                        drink.setCount(scanner.nextInt());
                    }
                    else if (i==5){
                        System.out.println("请选择点餐方式:1:单点,2:套餐,3:结束点餐。");
                        break;
                    }
                    else {
                        System.out.println("您的输入有误,请重新输入。");
                    }
                }
            }
            else  if(i==2){
                System.out.println("请选择套餐种类:1:儿童套餐,2:单人套餐,3,:双人套餐,4:家庭套餐,5:重新选择点餐方式。");
                while (scanner.hasNextInt()){
                    i=scanner.nextInt();
                    if (i==1){
                        System.out.println("请输入数量。");
                        child.setCount(scanner.nextInt());
                    }
                    else if(i==2){
                        System.out.println("请输入数量。");
                        single.setCount(scanner.nextInt());
                    }
                    else if (i==3){
                        System.out.println("请输入数量。");
                        couple.setCount(scanner.nextInt());
                    }
                    else if (i==4){
                        System.out.println("请输入数量。");
                        home.setCount(scanner.nextInt());
                    }
                    else if (i==5){
                        System.out.println("请选择点餐方式:1:单点,2:套餐,3:结束点餐。");
                        break;
                    }
                    else {
                        System.out.println("您的输入有误,请重新输入。");
                    }
                }
            }
            else if (i==3){
                break;
            }
            else {
                System.out.println("您的输入有误,请重新输入。");
            }
        }
        boolean flag=false;
        double pay=0;
        System.out.println("请问您要使用优惠券吗?Y:使用,N:不使用。");
        while (scanner.hasNext()){
            s=scanner.next();
            if (s.equals("Y")){
                flag=true;
                pay=hamburger.getCount()*hamburger.getSalePrice()+chicken.getCount()*chicken.getSalePrice()+fries.getCount()*fries.getSalePrice()+drink.getCount()*drink.getSalePrice()+child.getCount()*child.getPrize()+single.getCount()*single.getPrize()+couple.getCount()*couple.getPrize()+home.getCount()*home.getPrize();
                break;
            }
            else if (s.equals("N")){
                flag=false;
                pay=hamburger.getCount()*hamburger.getPrice()+chicken.getCount()*chicken.getPrice()+fries.getCount()*fries.getPrice()+drink.getCount()*drink.getPrice()+child.getCount()*child.getPrize()+single.getCount()*single.getPrize()+couple.getCount()*couple.getPrize()+home.getCount()*home.getPrize();
                break;
            }
            else {
                System.out.println("您的输入有误,请重新输入。");
            }
        }
        double money=0;
        System.out.println("共计"+pay+"元,请付款。");
        while (scanner.hasNextDouble()){
            money+=scanner.nextDouble();
            if (money<pay){
                System.out.println("您所付的金额不足,请继续付款。");
            }
            else {
                break;
            }
        }
        File f=new File("D:\\list.txt");//新建一个文件对象,如果不存在则创建一个该文件
        FileWriter fw;
        try{
            fw=new FileWriter(f);
            fw.write("餐品名称        餐品数量        餐品单价        总计\r\n");
            if(hamburger.getCount()>0||chicken.getCount()>0||fries.getCount()>0||drink.getCount()>0){
                if (flag){
                    if (hamburger.getCount()>0) {
                        fw.write("汉堡      " + hamburger.getCount() + "        " + hamburger.getSalePrice() + "        " + hamburger.getCount() * hamburger.getSalePrice()+"\r\n");
                    }
                    if (chicken.getCount()>0){
                        fw.write("炸鸡      "+chicken.getCount()+"      "+chicken.getSalePrice()+"      "+chicken.getCount()*chicken.getSalePrice()+"\r\n");
                    }
                    if (fries.getCount()>0){
                        fw.write("薯条      "+fries.getCount()+"        "+fries.getSalePrice()+"        "+fries.getCount()*fries.getSalePrice()+"\r\n");
                    }
                    if (drink.getCount()>0){
                        fw.write("饮料      "+drink.getCount()+"        "+drink.getSalePrice()+"        "+drink.getCount()*drink.getSalePrice()+"\r\n");
                    }
                }
                else{
                    if (hamburger.getCount()>0) {
                        fw.write("汉堡      " + hamburger.getCount() + "        " + hamburger.getPrice() + "        " + hamburger.getCount() * hamburger.getPrice()+"\r\n");
                    }
                    if (chicken.getCount()>0){
                        fw.write("炸鸡      "+chicken.getCount()+"      "+chicken.getPrice()+"      "+chicken.getCount()*chicken.getPrice()+"\r\n");
                    }
                    if (fries.getCount()>0){
                        fw.write("薯条      "+fries.getCount()+"        "+fries.getPrice()+"        "+fries.getCount()*fries.getPrice()+"\r\n");
                    }
                    if (drink.getCount()>0){
                        fw.write("饮料      "+drink.getCount()+"        "+drink.getPrice()+"        "+drink.getCount()*drink.getPrice()+"\r\n");
                    }
                }
            }
            if (child.getCount()>0){
                fw.write("儿童套餐            "+child.getCount()+"        "+child.getPrize()+"        "+child.getCount()*child.getPrize()+"\r\n");
            }
            if (single.getCount()>0){
                fw.write("单人套餐            "+single.getCount()+"       "+single.getPrize()+"       "+single.getCount()*single.getPrize()+"\r\n");
            }
            if (couple.getCount()>0){
                fw.write("双人套餐            "+couple.getCount()+"       "+couple.getPrize()+"       "+couple.getCount()*couple.getPrize()+"\r\n");
            }
            if (home.getCount()>0){
                fw.write("家庭套餐        "+home.getCount()+"       "+home.getPrize()+"       "+home.getCount()*home.getPrize()+"\r\n");
            }
            fw.write("合计:"+pay+"      找零:"+(money-pay)+"\r\n");
            fw.close();
        }
        catch(IOException e){
            System.out.print("IOException");
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值