模拟肯德基快餐店收银系统
同学们应该都去麦当劳或肯德基吃过快餐吧?请同学们参考肯德基官网的信息模拟肯德基快餐店的收银系统,合理使用C++/python/Java,结合设计模式(2种以上)至少实现系统的以下功能:
1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
5.模拟打印小票的功能(写到文件中)。
用时2周。
基本要求:
1.程序设计风格良好,控制台界面友好,最多两人一组完成任务。
2.实现功能测试代码,确保程序的健壮性。
3.画出使用的设计模式图。
提高要求:
1.实现可视化界面。
2.实现会员储值卡功能,完成储值卡消费。
3.实现当天营业额和餐品销量计算和统计,用数据库记录。
package zuoye4;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Properties;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Properties properties = new Properties();
BigDecimal order = order(properties);
BigDecimal bigDecimal1 = showCoupon(order);
System.out.println("请您付"+bigDecimal1.toString()+"元"); System.out.println("付:");
Scanner scanner = new Scanner(System.in);
String s = scanner.next();
System.out.println("收您"+s+"元");
BigDecimal bigDecimal = new BigDecimal(s);
BigDecimal divide = bigDecimal.subtract(bigDecimal1);
boolean b = ifEnough(bigDecimal1, bigDecimal);
if(b) {
System.out.println("为您找零" + divide.toString()); System.out.println("欢迎下次光临");
getPropertise(properties,bigDecimal1.toString(),bigDecimal.toString());
}
else {
getNotEnoughMoney(properties,bigDecimal1,bigDecimal);
}
System.out.println("注:您的小票已打印到 list.propertise文件上,你可核对信息哦");
}
public static void getPropertise(Properties properties,String price,String money){
FileOutputStream out = null;
try {
out = new FileOutputStream("list.propertise"); properties.setProperty("price",price);
properties.setProperty("money",money);
properties.store(out,"andieguo modify" + new Date().toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void getPropertise(Properties properties,String list){
FileOutputStream out = null;
try {
out = new FileOutputStream("list.propertise"); properties.setProperty("MealOrComboOrder",list);
properties.store(out,"andieguo modify" + new Date().toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void getNotEnoughMoney(Properties properties,BigDecimal price,BigDecimal money){
BigDecimal subtract = price.subtract(money);
System.out.println("您还需再付"+subtract.toString()+"元"); System.out.println("付:");
Scanner scanner = new Scanner(System.in);
String next = scanner.next();
BigDecimal bigDecimal = new BigDecimal(next);
if(bigDecimal.doubleValue()>=subtract.doubleValue()){
BigDecimal subtract1 = bigDecimal.subtract(subtract);
System.out.println("收您"+bigDecimal.toString()+"元");
System.out.println("为您找零" + subtract1.toString()+"元");
System.out.println("欢迎下次光临");
getPropertise(properties,price.toString(),price.add(subtract1).toString());
}
else {
getNotEnoughMoney(properties,subtract, bigDecimal);
}
}
public static boolean ifEnough(BigDecimal price,BigDecimal money){
if (money.doubleValue()-price.doubleValue()>=0){
return true;
}
return false;
}
public static BigDecimal showCoupon(BigDecimal price){
System.out.println("您有如下哪张优惠券吗(不能重叠使用,如没有请输入0)");
System.out.println(1.+" "+Coupon.COUPON1.getDescription());
System.out.println(2.+" "+Coupon.COUPON2.getDescription());
System.out.println(3.+" "+Coupon.COUPON3.getDescription());
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
if(i==0){
return price;
}
if(i==1){
double v = price.doubleValue();
if(v-100>=0){
BigDecimal multiply = price.subtract(new BigDecimal("20"));
return multiply;
}
System.out.println("您未购物超过100元,无法使用该优惠券");
return price;
}
if(i==2){
BigDecimal multiply = price.subtract(new BigDecimal("6"));
return multiply;
}
if(i==3){
BigDecimal multiply = price.multiply(new BigDecimal("0.88"));
return multiply;
}
return price;
}
public static void showNormalMeal() {
System.out.println("KFC为您提供如下菜单:");
System.out.println(1.+Meal.Roasted_chicken_burger.getName() + " " + Meal .Roasted_chicken_burger.getPrice().toString() + "元");
System.out.println(2.+Meal.Mini_burger.getName() + " " + Meal .Mini_burger.getPrice().toString() + "元");
System.out.println(3.+Meal.Extra_tasty_crispy_burger.getName() + " " + Meal .Extra_tasty_crispy_burger.getPrice().toString() + "元"); S
ystem.out.println(4.+Meal.Dragon_Twister.getName() + " " + Meal .Dragon_Twister.getPrice().toString() + "元");
System.out.println(5.+Meal.Hot_Wings.getName() + " " + Meal .Hot_Wings.getPrice().toString() + "元");
System.out.println(6.+Meal.Mexican_Twister.getName() + " " + Meal .Mexican_Twister.getPrice().toString() + "元");
System.out.println(7.+Meal.Popcorn_Chicken.getName() + " " + Meal .Popcorn_Chicken.getPrice().toString() + "元"); }
public static void showCombo()
{
System.out.println("KFC为您提供如下套餐");
System.out.println(1.+Combo.Bucket_meal.getName() + " " + Combo.Bucket_meal.getPrice().toString() + "元");
System.out.println(2.+Combo.Kids_meal.getName() + " " + Combo.Kids_meal.getPrice().toString() + "元");
System.out.println(3.+Combo.New_Orleans_roast_wings_combo.getName() + " " + Combo.New_Orleans_roast_wings_combo.getPrice().toString() + "元");
System.out.println(4.+Combo.Set_Meal.getName() + " " + Combo.Set_Meal.getPrice().toString() + "元");
}
public static BigDecimal order(Properties properties){
System.out.println("请您选择需要单品或者套餐 单品选择1 套餐选择2");
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
if(i==1){
showNormalMeal();
System.out.println("请您根据编号选择您的需要"+"产品之间用逗号分割");
Scanner scanner = new Scanner(System.in);
String next = scanner.next();
String[] split = next.split(",");
StringBuffer ss=new StringBuffer();
BigDecimal bigDecimal = new BigDecimal(0);
for (int o=0;o<split.length;o++){
bigDecimal=bigDecimal.add(Meal.getMealByNumber(split[o]).getPrice());
ss.append("Order:"+Meal.getMealByNumber(split[o]).getName()+" "+"Price:"+Meal.getMealByNumber(split[o]).getPrice().toString()+" ");
}
getPropertise(properties,ss.toString());
return bigDecimal;
}
else if(i==2){
showCombo();
System.out.println("请您根据编号选择您的需要"+"产品之间用逗号分割");
Scanner scanner = new Scanner(System.in);
String next = scanner.next();
String[] split = next.split(",");
BigDecimal bigDecimal = new BigDecimal(0);
StringBuffer ss=new StringBuffer();
for (int o=0;o<split.length;o++){
bigDecimal=bigDecimal.add(Combo.getCombo(split[o]).getPrice());
ss.append("Order:"+Combo.getCombo(split[o]).getName()+" "+"Price:"+Combo.getCombo(split[o]).getPrice().toString()+" ");
}
getPropertise(properties,ss.toString());
return bigDecimal;
}
return null;
}
}
enum Meal{
Roasted_chicken_burger("1","Roasted_chicken_burger",
new BigDecimal("19.00")),
Mini_burger("2","Mini_burger",new BigDecimal("21.54")),
Extra_tasty_crispy_burger ("3","Extra_tasty_crispy_burger",new BigDecimal("19.99")),
Dragon_Twister("4","Dragon_Twister",new BigDecimal("12.87")),
Hot_Wings("5","Hot_Wings",new BigDecimal("9.00")),
Mexican_Twister("6","Mexican_Twister",new BigDecimal("14.70")),
Popcorn_Chicken("7","Popcorn_Chicken",new BigDecimal("8.7")) ;
private String number;
private String name;
private BigDecimal price;
Meal(String number, String name, BigDecimal price) {
this.number = number;
this.name = name;
this.price = price;
}
public static Meal getMealByNumber(String number){
for(Meal e:Meal.values()){
if(e.getNumber().equals(number)){
return e;
}
}
return null;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
}
enum Combo{
Bucket_meal("1","Bucket_meal",new BigDecimal("78")),
Kids_meal("2","Kids_meal",new BigDecimal("69")),
New_Orleans_roast_wings_combo("3","New_Orleans_roast_wings_combo",new BigDecimal("52")),
Set_Meal ("4","Set_Meal",new BigDecimal("29")), ;
private String number;
private String name;
private BigDecimal price;
public static Combo getCombo(String number){
for(Combo e:Combo.values()){
if(e.getNumber().equals(number)){
return e;
}
}
return null;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
Combo(String number, String name, BigDecimal price) {
this.number = number;
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
}
enum Coupon{ COUPON1(1,"满100减20"), COUPON2(2,"立减6元"), COUPON3(3,"购买单品和套餐均可享受88折优惠") ;
private int number;
private String description;
Coupon(int number, String description) {
this.number = number;
this.description = description;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
运行结果: