java实现kfc点餐系统

1.基本需求

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

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

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

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

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

6.html.jsp实现可视化界面。

7.实现会员储值卡功能,完成储值卡消费。

8.实现当天营业额和餐品销量计算和统计,用数据库记录。Echars实现数据可视化


2.设计模式
单点食物:
  • 采用简单工厂,使用反射实现食品类的实例化
    • 工厂类 (SimFoodFactory)
套餐食物:
  • 采用抽象工厂,生成套餐系列产品(三个套餐)
    • 工厂类(ComboOneFactory ComboTwoFactory ComboThreeFactory )
数据库连接池
  • 采用单例模式,创建c3p0数据库连接池对象。

类图如下所示
在这里插入图片描述

3.实现
实体类
public class Food {
    public Integer id;//id
    public String name;//食品名
    public Double price;//食品价格
}

Drink类在Food类上的基础上有了容量属性

public  class  Drink extends Food{
    public Float capacity;
}

Eat类在Food类的基础上有了质量属性

public  class Eat extends Food {
    public Float quailty;
 } 

汉堡类继承Eat类


public class HamBean extends Eat {
    public HamBean() {
        this.id = 1;
        this.name = "汉堡";
        this.price = 12.0;
        this.quailty = 10f;
    }
}

薯条类继承Eat类

public class ChipsBean extends Eat {
    public ChipsBean() {
        this.id = 3;
        this.name = "薯条";
        this.price = 8.0;
        this.quailty = 50f;
    }
}

炸鸡类继承Eat类

public class ChickenBean extends Eat {
    public ChickenBean() {
        this.id = 2;
        this.name = "炸鸡";
        this.price = 25.0;
        this.quailty = 100f;
    }
}

可乐类继承Drink类

public class ColaBean extends Drink {
    public ColaBean() {
        this.id = 1;
        this.name = "可乐";
        this.price = 8.0;
        this.capacity = 100f;
    }
}

咖啡类继承Drink类

public class CafeBean extends Drink{
    public CafeBean() {
        this.id = 2;
        this.name = "咖啡";
        this.price = 12.0;
        this.capacity = 100f;
    }
}

果汁类继承Drink类

public class JuiceBean extends Drink {
    public JuiceBean() {
        this.id = 2;
        this.name = "咖啡";
        this.price = 12.0;
        this.capacity = 100f;
    }
}
简单工厂生产单件产品
/**
 * 简单工厂,通过反射加载食物实例(单点)
 */
public class SimFoodFactory {
    public Food getFood(Class c) {
        try {
            return (Food) Class.forName(c.getName()).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
抽象工厂实现生产套餐
public interface ComboFactory {
    List<Food> getCombo();
}

套餐1

/**
 * 1号组合套餐
 * 炸鸡和可乐
 */
public class ComboOneFactory implements ComboFactory {
    @Override
    public List<Food> getCombo() {
        List<Food> foodOneList= new ArrayList<Food>();//存储套餐产品
        Food chick = new ChickenBean();//实例化套餐内的产品
        Food cola = new ColaBean();
        chick.price = chick.price-2;//套餐的优惠,炸鸡价格减一元
        cola.price = cola.price-1;
        foodOneList.add(chick);
        foodOneList.add(cola);
        return foodOneList;//返回套餐集合
    }
}

套餐2

/**
 * 2号组合套餐
 * 薯条和果汁
 */
public class ComboTwoFactory implements ComboFactory {
    @Override
    public List<Food> getCombo() {
        List<Food> foodTwoList= new ArrayList<Food>();
        Food chips = new ChipsBean();
        Food  juice= new JuiceBean();
        chips.price = chips.price-1;//套餐组合的优惠
        juice.price = juice.price-0.5;
        foodTwoList.add(chips);
        foodTwoList.add(juice);
        return foodTwoList;
    }
}

套餐3

/**
 * 3号组合套餐
 * 汉堡和咖啡
 */
public class ComboThreeFactory implements ComboFactory {
    @Override
    public List<Food> getCombo() {
        List<Food> foodThreeList= new ArrayList<Food>();
        Food ham = new HamBean();
        Food  cafe= new CafeBean();
        ham.price = ham.price-1;//套餐组合的优惠
        cafe.price = cafe.price-0.5;
        foodThreeList.add(cafe);
        foodThreeList.add(ham);
        return foodThreeList;
    }
}
数据库连接池对象
public class DaoUtils {
    private static DataSource dataSource;
    public static DataSource getDataSource() {
        if(dataSource==null)
            dataSource = new ComboPooledDataSource();
        return dataSource;
    }
}
数据库连接池配置
<?xml version ="1.0" encoding= "UTF-8" ?>
<c3p0-config>
    <default-config>
        <property name="driverClass">com.mysql.jdbc.Driver</property>
        <property name="jdbcUrl">jdbc:mysql://localhost:3306/kfc?useUnicode=true&amp;characterEncoding=UTF8</property>
        <property name
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值