GitHub: https://github.com/Yangjiaxin121/JavaProject/tree/master/zuoye/src/KFC
同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++/python/Java,结合设计模式(2种以上)至少实现系统的以下功能:
- 正常餐品结算和找零
- 基本套餐结算和找零。
- 使用优惠劵购买餐品结算和找零。
- 可在一定时间段参与店内活动(自行设计或参考官网信息)。
- 模拟打印小票的功能(写到文件中)。
用时2周。
基本要求:
程序设计风格良好,控制台界面友好,最多两人一组完成任务。
实现功能测试代码,确保程序的健壮性。
画出使用的设计模式图。
提高要求:
实现可视化界面。
实现会员储值卡功能,完成储值卡消费。
实现当天营业额和餐品销量计算和统计,用数据库记录。
对于这道题,我首先想到的是使用工厂模式,通过继承Food抽象类,创建相应的实体类,然后通过点餐的选项然后传入需要的实例对象的name,之后通过工厂模式创建出来,然后获取他们的价格属性,并进行计算。同时我还做了可视化的处理,并添加了数据库的连接。
- 首先创建实体类:
package KFC;
public abstract class Food {
String name;
double price;
public Food() {
}
public Food(String name, double price) {
super();
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public void select() {
System.out.println("点了food");
}
}
package KFC;
public class ChickenRice extends Food{
public ChickenRice() {
super("鸡排饭",20);
// TODO Auto-generated constructor stub
}
}
- 之后是通过工厂模式创建
public Food getFood(String foodType) {
if (foodType == null) {
return null;
}
if (foodType.equalsIgnoreCase("鸡排饭")) {
return new ChickenRice();
} else if (foodType.equalsIgnoreCase("汉堡包")) {
return new Hamburger();
} else if (foodType.equalsIgnoreCase("全家桶")) {
return new Buckets();
} else if (foodType.equals("奶茶")) {
return new Milktea();
} else if (foodType.equals("咖啡")) {
return new Coffee();
} else if (foodType.equals("果汁")) {
return new Juice();
} else if (foodType.equals("蛋挞")) {
return new EggTart();
} else if (foodType.equals("薯条")) {
return new French();
} else if (foodType.equals("鸡米花")) {
return new PopcornChicken();
}
return null;
}