本系统完整代码已上传到本博客附下载链接:
下载链接:KFC肯德基收银系统

一、 题目要求`
模拟肯德基快餐店的收银系统,合理使用C++或Java或Python结合设计模式(2种以上)至少实现系统的以下功能:
1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动(自行设计或参考官网信息)。
5.模拟打印小票的功能(写到文件中)。

基本要求:
1.程序设计风格良好,控制台界面友好,最多两人一组完成任务。
2.实现功能测试代码,确保程序的健壮性。
3.画出使用的设计模式图。
提高要求:
1.实现可视化界面(使用MFC)。
2.实现会员储值卡功能,完成储值卡消费。
3.实现当天营业额和餐品销量计算和统计,用数据库记录。

二、相关设计模式:
简单工厂模式、抽象工厂模式和单例模式。

三、
package ComboMeal(抽象工厂模式)

package ComboMeal;import java.util.HashSet;
import java.util.Set;import Meals.*;public class Combo1 implements ComboFactory{@Overridepublic Set<Food> setCombo() {//炸鸡肥宅水套餐Set<Food> foodOneList= new HashSet<Food>();Food chick = new Chicken();//实例化套餐内的产品Food cola = new Cola();chick.price = chick.price-2;//套餐的优惠,炸鸡价格减两元cola.price = cola.price-1;foodOneList.add(chick);foodOneList.add(cola);return foodOneList;//返回套餐集合}}
package ComboMeal;import java.util.HashSet;
import java.util.Set;import Meals.*;public class Combo2 implements ComboFactory{public Set<Food> setCombo() {// 薯条与果汁套餐Set<Food> foodTwoList= new HashSet<Food>();Food chips = new Chips();Food  juice= new Juice();chips.price = chips.price-1;//套餐组合的优惠juice.price = juice.price-1.5;foodTwoList.add(chips);foodTwoList.add(juice);return foodTwoList;}
}
package ComboMeal;import java.util.HashSet;
import java.util.Set;import Meals.*;public class Combo3 implements ComboFactory{@Overridepublic Set<Food> setCombo() {//汉堡咖啡套餐Set<Food> foodThreeList= new HashSet<Food>();Food ham = new Hamburger();Food  cafe= new Coffee();ham.price = ham.price-1;//套餐组合的优惠cafe.price = cafe.price-0.5;foodThreeList.add(ham);foodThreeList.add(cafe);return foodThreeList;}}
package ComboMeal;
import java.util.Set;import Meals.*;
public interface ComboFactory {//public ComboFactory getComboMeals();public Set<Food> setCombo();}

package Meals

package Meals;public class Chicken extends Eat {public Chicken() {// TODO 自动生成的构造函数存根name="炸鸡";price=6.0;quailty=0.069;
}@Override
public double getPrice() {// TODO 自动生成的方法存根return price;
}
}
package Meals;public class Chips extends Eat {public Chips() {// TODO 自动生成的构造函数存根name="薯条";price=5.0;quailty=0.050;
}@Override
public double getPrice() {// TODO 自动生成的方法存根return price;
}
}
package Meals;public class Coffee extends Drink {public Coffee() {// TODO 自动生成的构造函数存根name="咖啡";price=5.0;capacity=500.0;
}@Override
public double getPrice() {// TODO 自动生成的方法存根return price;
}
}
package Meals;public class Cola extends Drink{public Cola() {// TODO 自动生成的构造函数存根name="可乐";price=5.0;capacity=500.0;
}@Override
public double getPrice() {// TODO 自动生成的方法存根return price;
}
}
package Meals;public abstract class Drink extends Food {Double capacity;
}
package Meals;public abstract class Eat extends Food {Double quailty;
}
package Meals;public abstract class Food {public Double price;public String name;public abstract double getPrice();public int hashCode(){return 1;}public boolean equals(Object obj){ Food food=(Food)obj;if(obj==null)return false;if(this.name.equals(food.name)&&this.price.equals(food.price)
)return true;elsereturn false;}}
package Meals;public class Hamburger extends Eat {public Hamburger() {// TODO 自动生成的构造函数存根name="汉堡";price=9.0;quailty=0.2;
}@Override
public double getPrice() {// TODO 自动生成的方法存根return price;
}
}
package Meals;public class Juice extends Drink {public Juice() {// TODO 自动生成的构造函数存根name="果汁";price=5.0;capacity=500.0;
}@Override
public double getPrice() {// TODO 自动生成的方法存根return price;
}
}
package Meals;public class SimpleFactory {public static Food setFood(Class c) {try {return (Food) Class.forName(c.getName()).newInstance();} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {e.printStackTrace();}return null;}
}

Swing 实现可视化界面
package Windows;

package Windows;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;import javax.swing.*;public class HomePage extends JFrame{JButton orderButton;JButton checkButton;JButton printButton;JButton storageButton;public HomePage(){setBg();orderButton = new JButton("点餐");checkButton = new JButton("介绍");printButton = new JButton("优惠");storageButton = new JButton("退出");this.setTitle("KFC");this.setSize(600,400);this.setLocation(300, 100);this.setLayout(null);orderButton.setBounds(120,130,60,30);this.add(orderButton);orderButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubOrderyFrame orderyFrame = new OrderyFrame();orderyFrame.setFrame(orderyFrame);orderyFrame.MyFrame();}});checkButton.setBounds(400,130,60,30);this.add(checkButton);checkButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub//CheckFrame check = new CheckFrame();IntroFrame introFrame = new IntroFrame();}});printButton.setBounds(120,200,60,30);this.add(printButton);printButton.addActionListener(new ActionListener() {@Override       public void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub//PrintFrame print = new PrintFrame();Date time1 = new Date();int hour=time1.getHours();if(hour>12&&hour<13) {JOptionPane.showMessageDialog(null,"现在是优惠时间,任意商品5折优惠","0.0",JOptionPane.INFORMATION_MESSAGE);}else {JOptionPane.showMessageDialog(null,"很抱歉,现在不是优惠时间段!","0.0",JOptionPane.INFORMATION_MESSAGE);}}});storageButton.setBounds(400,200,60,30);this.add(storageButton);storageButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub//StorageFrame storage = new StorageFrame();dispose();}});JLabel label = new JLabel("欢迎来到KFC",JLabel.CENTER);label.setFont(new Font("宋体",Font.PLAIN,20));label.setBounds( 200, 10, 200, 80);this.add(label);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public void setBg(){   ((JPanel)this.getContentPane()).setOpaque(false);   ImageIcon img = new ImageIcon  ("kfc.gif");   JLabel background = new JLabel(img);  this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));   background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());   } }
package Windows;import java.awt.Font;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class IntroFrame extends JFrame{public IntroFrame() {setBg();this.setLayout(null);this.setTitle("KFC");this.setSize(600,400);this.setLocation(300, 100);this.setLayout(null);JLabel label1 = new JLabel("KFC's introduce",JLabel.CENTER);label1.setFont(new Font("宋体",Font.PLAIN,20));label1.setBounds( 200, 10, 200, 80);String string = "“欢迎光临本店”、“尽情自在肯德基”。";JLabel label2 = new JLabel(string);label2.setBounds( 100, 90,  300, 80);  String string3 = "本店有随机抽取优惠卷活动,只要下单即可获得随机优惠卷";JLabel label3 = new JLabel(string3);label3.setBounds( 100, 150,  400, 80); String string4 = "凡是在12:00到13:00之间下单的顾客可享受5折优惠";JLabel label4 = new JLabel(string4);label4.setBounds( 100, 210,  400, 80);    this.add(label1);this.add(label2);this.add(label3);this.add(label4);//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public void setBg(){   ((JPanel)this.getContentPane()).setOpaque(false);   ImageIcon img = new ImageIcon  ("kfc.gif");   JLabel background = new JLabel(img);  this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));   background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());   } }
package Windows;import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;public class JDBCUtil {static String driverClass=null;static String url=null;static String user=null;static String password= null;static {//工具类中使用静态代码块,读取属性try {Properties properties = new Properties();/*** 使用类加载器读取src底下的资源文件;*/// TODO :: val is is null//InputStream is =JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");//当点properties文件位于src中时,可用;InputStream is =new FileInputStream("jdbc.properties"); //当点properties文件位于更目录下,即JDBC practice01下时,可用properties.load(is);driverClass=properties.getProperty("driverClass");url=properties.getProperty("url");user=properties.getProperty("user");password=properties.getProperty("password");} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}public static Connection getConn() {Connection conn=null;try {System.out.println("a");// Class.forName(driverClass);       //可注释掉,已自动连接conn = DriverManager.getConnection(url,user,password);} catch (NullPointerException | SQLException e) {// TODO: handle exceptione.printStackTrace();}return conn;}public static void release(Connection conn, Statement createStatement, ResultSet rSet) {closeConn(conn);closecreateStatement(createStatement);closerSet(rSet);}private static void closeConn(Connection conn) {try {if (conn != null) {conn.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {conn = null;}}private static void closecreateStatement(Statement createStatement) {try {if (createStatement != null) {createStatement.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {createStatement = null;}}private static void closerSet(ResultSet rSet) {try {if (rSet != null) {rSet.close();}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {rSet = null;}}
}
package Windows;
import javax.swing.*;
public class Main_in extends JFrame{public static void main(String[] args) {HomePage t = new HomePage();}}
package Windows;import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import Meals.*;
import java.io.File;
import java.io.Writer;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import ComboMeal.*;
import ComboMeal.ComboFactory;public class OrderyFrame extends JFrame{public static int n1=0,n2=0,n3=0,n4=0,n5=0,n6=0,t1=0,t2=0,t3=0;/*炸鸡,汉堡,薯条,咖啡,果汁,可乐*/Connection conn =null;PreparedStatement ptmt =null;Statement createStatement =null;ResultSet rSet =null;public static  Set<Food> menuSet = new HashSet<>();public File file=new File("小票.txt");Paywin payframe=Paywin.getInstance();private  OrderyFrame q;public void setFrame(OrderyFrame qq) {q = qq;}public void  MyFrame() {setBg();setTitle("KFC界面");this.setSize(700,400);this.setLocation(300, 100);this.setLayout(null);JLabel label = new JLabel("欢迎来到KFC点餐",JLabel.CENTER);label.setFont(new Font("宋体",Font.PLAIN,20));label.setBounds( 200, 10, 200, 80);this.add(label);String str1 = "主食";JLabel label_1 = new JLabel(str1);label_1.setFont(new Font("宋体",Font.PLAIN,15));label_1.setBounds( 100, 60, 240, 80);this.add(label_1);String str2 = "饮料";JLabel label_2 = new JLabel(str2);label_2.setFont(new Font("宋体",Font.PLAIN,15));label_2.setBounds( 280, 60, 240, 80);this.add(label_2);String str3 = "套餐";JLabel label_3 = new JLabel(str3);label_3.setFont(new Font("宋体",Font.PLAIN,15));label_3.setBounds( 480, 60, 240, 80);this.add(label_3);String food1 = "炸鸡";JCheckBox checkBox1 = new JCheckBox(food1);checkBox1.setFont(new Font("宋体",Font.PLAIN,15));checkBox1.setBounds( 100, 110, 90, 70);this.add(checkBox1);JLabel priceLabel1 = new JLabel("6元");priceLabel1.setFont(new Font("宋体",Font.PLAIN,15));priceLabel1.setBounds( 190, 110, 100, 70);this.add(priceLabel1);checkBox1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();if (checkBox.isSelected()) {n1+=1;menuSet.add(SimpleFactory.setFood(Chicken.class));}else {n1-=1;menuSet.remove(SimpleFactory.setFood(Chicken.class));}}});String food2 = "汉堡";JCheckBox checkBox2 = new JCheckBox(food2);checkBox2.setFont(new Font("宋体",Font.PLAIN,15));checkBox2.setBounds( 100, 160, 90, 70);this.add(checkBox2);JLabel priceLabel2 = new JLabel("9元");priceLabel2.setFont(new Font("宋体",Font.PLAIN,15));priceLabel2.setBounds( 190, 160, 100, 70);this.add(priceLabel2);checkBox2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();if (checkBox.isSelected()) {n2+=1;menuSet.add(SimpleFactory.setFood(Hamburger.class));}else {n2-=1;menuSet.remove(SimpleFactory.setFood(Hamburger.class));}}});String food3 = "薯条";JCheckBox checkBox3 = new JCheckBox(food3);checkBox3.setFont(new Font("宋体",Font.PLAIN,15));checkBox3.setBounds( 100, 210, 90, 70);this.add(checkBox3);JLabel priceLabel3 = new JLabel("5元");priceLabel3.setFont(new Font("宋体",Font.PLAIN,15));priceLabel3.setBounds( 190, 210, 100, 70);this.add(priceLabel3);checkBox3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();if (checkBox.isSelected()) {n3+=1;menuSet.add(SimpleFactory.setFood(Chips.class));}else {n3-=1;menuSet.remove(SimpleFactory.setFood(Chips.class));}}});String food4 = "咖啡";JCheckBox checkBox4 = new JCheckBox(food4);checkBox4.setFont(new Font("宋体",Font.PLAIN,15));checkBox4.setBounds( 280, 110, 90, 70);this.add(checkBox4);JLabel priceLabel4 = new JLabel("5元");priceLabel4.setFont(new Font("宋体",Font.PLAIN,15));priceLabel4.setBounds(370, 110, 90, 70);this.add(priceLabel4);checkBox4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();if (checkBox.isSelected()) {n4+=1;menuSet.add(SimpleFactory.setFood(Coffee.class));}else {n4-=1;menuSet.remove(SimpleFactory.setFood(Coffee.class));}}});String food5 = "果汁";JCheckBox checkBox5 = new JCheckBox(food5);checkBox5.setFont(new Font("宋体",Font.PLAIN,15));checkBox5.setBounds( 280, 160, 90, 70);this.add(checkBox5);JLabel priceLabel5 = new JLabel("5元");priceLabel5.setFont(new Font("宋体",Font.PLAIN,15));priceLabel5.setBounds(370, 160, 100, 70);this.add(priceLabel5);checkBox5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();if (checkBox.isSelected()) {n5+=1;menuSet.add(SimpleFactory.setFood(Juice.class));}else {n5-=1;menuSet.remove(SimpleFactory.setFood(Juice.class));}}});String food6 = "可乐";JCheckBox checkBox6 = new JCheckBox(food6);checkBox6.setFont(new Font("宋体",Font.PLAIN,15));checkBox6.setBounds( 280, 210, 90, 70);this.add(checkBox6);JLabel priceLabel6 = new JLabel("5元");priceLabel6.setFont(new Font("宋体",Font.PLAIN,15));priceLabel6.setBounds(370, 210, 100, 70);this.add(priceLabel6);checkBox6.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();if (checkBox.isSelected()) {n6+=1;menuSet.add(SimpleFactory.setFood(Cola.class));}else {n6-=1;menuSet.remove(SimpleFactory.setFood(Cola.class));}}});String food7 = "汉堡咖啡套餐";JCheckBox checkBox7 = new JCheckBox(food7);checkBox7.setFont(new Font("宋体",Font.PLAIN,15));checkBox7.setBounds( 480, 110, 120, 70);this.add(checkBox7);JLabel priceLabel7 = new JLabel("12.5元");priceLabel7.setFont(new Font("宋体",Font.PLAIN,15));priceLabel7.setBounds(610, 110, 100, 70);this.add(priceLabel7);checkBox7.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();ComboFactory c1=new Combo3();Set<Food> s1=c1.setCombo();if (checkBox.isSelected()) {t3+=1;menuSet.addAll(s1);}else {t3-=1;menuSet.removeAll(s1);}}});String food8 = "炸鸡可乐套餐";JCheckBox checkBox8 = new JCheckBox(food8);checkBox8.setFont(new Font("宋体",Font.PLAIN,15));checkBox8.setBounds( 480, 160,120, 70);this.add(checkBox8);JLabel priceLabel8 = new JLabel("8元");priceLabel8.setFont(new Font("宋体",Font.PLAIN,15));priceLabel8.setBounds(610, 160, 100, 70);this.add(priceLabel8);checkBox8.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();ComboFactory c1=new Combo1();Set<Food> s1=c1.setCombo();if (checkBox.isSelected()) {t1+=1;menuSet.addAll(s1);}else {t1-=1;menuSet.removeAll(s1);}}});String food9 = "薯条果汁套餐";JCheckBox checkBox9 = new JCheckBox(food9);checkBox9.setFont(new Font("宋体",Font.PLAIN,15));checkBox9.setBounds( 480, 210, 120, 70);this.add(checkBox9);JLabel priceLabel9 = new JLabel("8.5元");priceLabel9.setFont(new Font("宋体",Font.PLAIN,15));priceLabel9.setBounds(610, 210, 100, 70);this.add(priceLabel9);checkBox9.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// TODO 自动生成的方法存根JCheckBox checkBox = (JCheckBox) e.getSource();ComboFactory c1=new Combo2();Set<Food> s1=c1.setCombo();if (checkBox.isSelected()) {t2+=1;System.out.println("a1");menuSet.addAll(s1);}else {t2-=1;menuSet.removeAll(s1);System.out.println("a2");}}});JButton b1 = new JButton("预定");b1.setBounds(450, 300, 60, 30);this.add(b1);b1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {float price1 = 0,price2 = 0;PreparedStatement st =null;try {conn = JDBCUtil.getConn();if(n1!=0) {st =conn.prepareStatement("insert into table1 values('chicken',?,?)");st.setInt(1, n1);st.setInt(2, 6*n1);st.executeUpdate();}if(n2!=0) {st =conn.prepareStatement("insert into table1 values('hamburger',?,?)");st.setInt(1, n2);st.setInt(2, 9*n2);st.executeUpdate();}if(n3!=0) {st =conn.prepareStatement("insert into table1 values('chips',?,?)");st.setInt(1, n3);st.setInt(2, 5*n3);st.executeUpdate();}if(n4!=0) {st =conn.prepareStatement("insert into table1 values('coffee',?,?)");st.setInt(1, n4);st.setInt(2, 5*n4);st.executeUpdate();}if(n5!=0) {st =conn.prepareStatement("insert into table1 values('juice',?,?)");st.setInt(1, n5);st.setInt(2, 5*n5);st.executeUpdate();}if(n6!=0) {st =conn.prepareStatement("insert into table1 values('cola',?,?)");st.setInt(1, n6);st.setInt(2, 5*n6);st.executeUpdate();}if(t1!=0) {st =conn.prepareStatement("insert into table2 values('combo1',?,?)");st.setInt(1, t1);st.setFloat(2, (float) (8*t1));st.executeUpdate();}if(t2!=0) {st =conn.prepareStatement("insert into table2 values('combo2',?,?)");st.setInt(1, t2);st.setFloat(2, (float) (8.5*n6));st.executeUpdate();}if(t3!=0) {st =conn.prepareStatement("insert into table2 values('combo3',?,?)");st.setInt(1, t3);st.setFloat(2, (float) (12.5*t3));st.executeUpdate();}} catch (SQLException | NullPointerException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}finally {JDBCUtil.release(conn, createStatement, rSet);}Connection conn =null;Statement createStatement =null;ResultSet rSet =null;try {conn = JDBCUtil.getConn();createStatement = conn.createStatement();//查询String sql="select sum(ptotal) from table1";createStatement.execute(sql);   //execute执行 //返回结果rSet =createStatement.executeQuery(sql);while(rSet.next()) {price1=rSet.getFloat(1);System.out.println(rSet.getFloat(1));}} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}finally {JDBCUtil.release(conn, createStatement, rSet);}try {conn = JDBCUtil.getConn();createStatement = conn.createStatement();//查询String sql="select sum(tptotal) from table2";createStatement.execute(sql);   //execute执行 //返回结果rSet =createStatement.executeQuery(sql);while(rSet.next()) {price2=rSet.getFloat(1);                            //获取聚集函数sum时不确定长度时用ResaultSet.getlong(1);System.out.println(rSet.getFloat(1));}} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}System.out.println("套餐的总收益为:"+price2);System.out.println("单品的总收益为:"+price1);System.out.println("当日收益总额为:"+price1+price2);if(price1!=0&&price2!=0) {try {st =conn.prepareStatement("insert into table3 values(?,?,?)");st.setFloat(1, price1);st.setFloat(2, price2);st.setFloat(3, price1+price2);st.executeUpdate();} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}finally {JDBCUtil.release(conn, createStatement, rSet);}}JOptionPane.showMessageDialog(q,"预定成功","0.0",JOptionPane.INFORMATION_MESSAGE);try {  //获取当前的日期Date date = new Date();//设置要获取到什么样的时间SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//获取String类型的时间String createdate = sdf.format(date);Writer out = new FileWriter(file,true);out.write("-------------------------------------------------------------\r\n");for(Food x:menuSet)out.write(x.name+"  价格:"+x.price+"\r\n");out.write(createdate+"\r\n");out.write("-------------------------------------------------------------\r\n");out.close();}catch(IOException a) {System.out.println("写入文件问题"+a.toString());}for(Food x:menuSet)System.out.println(x.name);payframe.frame();}});//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public static double getTotalPrice() {double totalPrice = 0.0;//Food food;for (Food string : menuSet) {//food = getFood(string);totalPrice = totalPrice + string.getPrice();}System.out.println(totalPrice);return totalPrice;}//使用 getFood方法获取形状类型的对象public void setBg(){   ((JPanel)this.getContentPane()).setOpaque(false);   ImageIcon img = new ImageIcon  ("kfc.gif");   JLabel background = new JLabel(img);  this.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));   background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());   } }
package Windows;import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;public class Paywin {private static Paywin instance=null; private Paywin() { }//静态公有工厂方法,返回唯一实例public static Paywin getInstance() {if(instance==null)instance=new Paywin();    return instance;}public void frame() {JFrame frame = new JFrame("付款");((JPanel)frame.getContentPane()).setOpaque(false);   ImageIcon img = new ImageIcon  ("kfc.gif");   JLabel background = new JLabel(img);  frame.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));   background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());   double totalPrice = OrderyFrame.getTotalPrice();Date time1 = new Date();int hour=time1.getHours();if(hour>12&&hour<13) {JLabel priceLabel = new JLabel("请付款"+ totalPrice*0.5 +"元");priceLabel.setFont(new Font("宋体",Font.PLAIN,15));priceLabel.setBounds(100, 100, 120, 30);frame.add(priceLabel);}else {JLabel priceLabel = new JLabel("请付款"+ totalPrice +"元");priceLabel.setFont(new Font("宋体",Font.PLAIN,15));priceLabel.setBounds(100, 100, 120, 30);frame.add(priceLabel);}int couponsPrice = (int) (Math.random()*(4-1+1)+1);JLabel coupons = new JLabel("优惠券" + couponsPrice);coupons.setFont(new Font("宋体",Font.PLAIN,15));coupons.setBounds(100, 130, 120, 30);frame.add(coupons);JLabel payLabel = new JLabel("付款");payLabel.setFont(new Font("宋体",Font.PLAIN,15));payLabel.setBounds(100, 160, 120, 30);frame.add(payLabel);JTextField jTextArea = new JTextField(200);jTextArea.setBounds(140, 160, 120, 30);frame.add(jTextArea);frame.setSize(300, 300);frame.setBounds(100, 100, 300, 300);frame.setLayout(null);JButton paid = new JButton("付款");paid.setBounds(100, 200, 90, 30);paid.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubDouble a;try{a=Double.parseDouble(jTextArea.getText());}catch(NumberFormatException exception) {a=0.0;}double result = a + couponsPrice - totalPrice;if (result<0) {coupons.setText("金额不够支付");} else {coupons.setText("找零:"+ result);}}});frame.add(paid);frame.setVisible(true);}}

jdbc.properties文件

driverClass=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/kfcsale
user=root
password= 123

模拟肯德基KFC快餐店收银系统相关推荐

  1. 设计模式之Java语言模拟肯德基点餐收银系统

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

  2. 肯德基点餐收银系统(java GUI实现)

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

  3. 快餐店收银系统Pos学习笔记

    #快餐店收银系统Pos学习笔记 ##第一节mockplus 这是一个产品经理使用的软件,可以大概地做出网页样式. ##第二节安装vue-cli环境 mpm install vue-cli -g 全局下 ...

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

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

  5. JAVA肯德基快餐店收银系统

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

  6. C++实现模拟麦当劳的收银系统

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

  7. Vue学习之路(8)------快餐店收银系统

    转载:http://jspang.com 第1节:Mockplus把我们的想法画出来 第2节:Vue-cli搭建开发环境 第3节:搞定项目图标Iconfont 第4节:编写独立的侧边栏导航组件 第5节 ...

  8. Vue实战视频-快餐店收银系统

    博客写的很用心: http://jspang.com/2017/05/22/vuedemo/

  9. 基于MFC的肯德基快餐店的收银系统

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

最新文章

  1. mysql query日期_如何获取mysql中两个日期之间的日期列表select query
  2. 使用python来操作redis用法详解
  3. 二,八,十,十六进制之间转换的相应方法
  4. c语言选择排序_C语言——选择排序
  5. php static_castunsigned int,static_cast揭密
  6. statistic在c语言中的作用,模型评价除了C-statistic,还能用什么指标?
  7. python-rrdtool python-pyrrd
  8. openwrt 自动签到插件-食用指南
  9. linux命令安装tongweb教程,【中间件】TongWeb安装
  10. 电影院购票系统ssm (含论文)
  11. 调用服务器直接打印文件,使用 LP 打印命令设置直接连接的打印机
  12. oracle 建表引号,oracle 创建表加双引号作用
  13. 大多数计算机有几个cpu,多处理器分配
  14. 千人千面、个性化推荐:解读数据赋能商家背后的AI技术
  15. 文本框失去焦点事件、获得焦点事件
  16. [Microsoft Lync] Find a previous conversation - Chat History
  17. 最新江苏安全员B考试单选练习题库
  18. java大学生网上请假系统ssm框架
  19. ECharts 中的事件和行为
  20. 十二、Hi3556移植RTL8189 WIFI驱动

热门文章

  1. 关于python如何编写注释(包含中文)及出现SyntaxError: Non-UTF-8 code starting with ‘\xca‘ in file错误解决方案
  2. ZooKeeper 的 Watch 机制是什么?
  3. 二叉树存储结构 mysql_为什么mysql索引选择b+树作为底层存储结构?
  4. android开发平台的框架原理,赶紧收藏起来
  5. Apollo + Springboot 整合(多环境版)
  6. android vold磁盘管理
  7. h5中的图片点击放大
  8. Gradle 2.0 用户指南翻译——第五十章. 依赖管理
  9. Java的Map(映射)特性及编程思想
  10. 使用头文件winbase.h的错误