Java實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng)過(guò)程解析
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng),模擬肯德基快餐店的收銀系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
同學(xué)們應(yīng)該都去麥當(dāng)勞或肯德基吃過(guò)快餐吧?請(qǐng)同學(xué)們參考肯德基官網(wǎng)的信息模擬肯德基快餐店的收銀系統(tǒng),合理使用C++/python/Java,結(jié)合設(shè)計(jì)模式(2種以上)至少實(shí)現(xiàn)系統(tǒng)的以下功能:
1.正常餐品結(jié)算和找零。
2.基本套餐結(jié)算和找零。
3.使用優(yōu)惠劵購(gòu)買餐品結(jié)算和找零。
4.可在一定時(shí)間段參與店內(nèi)活動(dòng)(自行設(shè)計(jì)或參考官網(wǎng)信息)。
5.模擬打印小票的功能(寫到文件中)。
類圖:

建立IFood接口實(shí)現(xiàn)各類食物信息的打印:
public interface IFood {
/**
* 打印輸出食物信息
* @return
*/
String printMesage();
}
抽象類AbstractBaseFood
public class AbstractBaseFood {
// 類別
protected String kind;
// 數(shù)量
protected int num;
// 價(jià)格
protected float price;
//找零
// 合計(jì)
public float totalPrice()
{
return this.num * this.price;
}
}
各類果汁的基類Baverage:
public abstract class Beverage extends AbstractBaseFood implements IFood
{
public String printMesage()
{
return ("--" + this.kind + "飲料,\t單價(jià):" + this.price + ",\t數(shù)量:" + this.num + ",\t合計(jì):" + this.totalPrice());
}
}
建立Baverage的具體實(shí)現(xiàn)類ChinaBaverage:
public class ChinaBeverage extends Beverage
{
public ChinaBeverage(int num)
{
this.kind = "可樂(lè)";
this.price = 6.0f;
this.num = num;
}
}
以此類推分別建立 ChickenWing,F(xiàn)renchFries,Hamburg抽象類和它們的實(shí)現(xiàn)類ChinaChickenWing,FrenchFries,Hamburg
建立抽象工廠IKfcFactory:
public interface IKfcFactory
{
// 生產(chǎn)漢堡
public ChinaHamburg createHamburg(int num);
// 生產(chǎn)薯?xiàng)l
public xtx.FrenchFries createFrenchFries(int num);
// 生產(chǎn)雞翅
public ChinaChickenWings createChickenWings(int num);
// 生產(chǎn)飲料
public ChinaBeverage createBeverage(int num);
}
建立IKfcFactory的實(shí)現(xiàn)類ChinaFactory:
public class ChinaKfcFactory implements IKfcFactory
{
// 生產(chǎn)可樂(lè)
public ChinaBeverage createBeverage(int num)
{
return new ChinaBeverage(num);
}
// 生產(chǎn)奧爾良烤雞翅
public ChinaChickenWings createChickenWings(int num)
{
return new ChinaChickenWings(num);
}
// 生產(chǎn)薯?xiàng)l
public ChinaFrenchFries createFrenchFries(int num)
{
return new ChinaFrenchFries(num);
}
// 生產(chǎn)麻辣風(fēng)味雞腿漢堡
public ChinaHamburg createHamburg(int num)
{
return new ChinaHamburg(num);
}
}
建立Customer類實(shí)現(xiàn)食物的選擇和文件存儲(chǔ):
package xtx.factory.custom;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import xtx.ChinaBeverage;
import xtx.ChinaChickenWings;
import xtx.ChinaFrenchFries;
import xtx.IKfcFactory;
import xtx.ChinaHamburg;
public class Customer
{
// 抽象工廠
private IKfcFactory kfcFactory;
// 構(gòu)造方法將抽象工廠作為參數(shù)傳入
public Customer(IKfcFactory kfcFactory2)
{
this.kfcFactory = kfcFactory2;
}
/**
* 訂購(gòu)食物
* @throws IOException
*/
private String s[] =new String[5];
public void showbill() throws IOException{
BufferedWriter bw=new BufferedWriter(new FileWriter("D://workspace2Eclipse//xtx//src//xtx//factory//custom//show.txt",true));
bw.write("---------------------賬單如下---------------------");
bw.newLine();
for(int i=0;i<5;i++){
bw.write(s[i]);
bw.newLine();
bw.flush();
}
}
// 訂購(gòu)麻辣雞腿漢堡
public float orderHamburg(int num) throws IOException
{
// 獲得麻辣雞腿漢堡
ChinaHamburg hamburg = kfcFactory.createHamburg(num);
// 輸出訂購(gòu)信息
System.out.print(hamburg.printMesage());
s[0]=hamburg.printMesage();
System.out.print("\n");
// 返回總價(jià)
return hamburg.totalPrice();
}
// 訂購(gòu)?qiáng)W爾良烤雞翅
public float orderChickenWings(int num)
{
// 獲得奧爾良烤雞翅
ChinaChickenWings chickenWings = kfcFactory.createChickenWings(num);
// 輸出訂購(gòu)信息
System.out.print(chickenWings.printMesage());
s[1]=chickenWings.printMesage();
System.out.print("\n");
// 返回總價(jià)
return chickenWings.totalPrice();
}
// 訂購(gòu)薯?xiàng)l
public float orderFrenchFries(int num)
{
// 獲得薯?xiàng)l
ChinaFrenchFries frenchFries = (ChinaFrenchFries) ((IKfcFactory) kfcFactory).createFrenchFries(num);
// 輸出訂購(gòu)信息
System.out.print(frenchFries.printMesage());
s[2]=frenchFries.printMesage();
System.out.print("\n");
// 返回總價(jià)
return frenchFries.totalPrice();
}
// 訂購(gòu)可樂(lè)
public float orderBeverage(int num)
{
// 獲得可樂(lè)
ChinaBeverage beverage = kfcFactory.createBeverage(num);
// 輸出訂購(gòu)信息
System.out.print(beverage.printMesage());
s[3]=beverage.printMesage();
System.out.print("\n");
return beverage.totalPrice();
}
//訂購(gòu)套餐一
public float ordercombo1(int num)
{
// 獲得可樂(lè)
ChinaBeverage beverage = kfcFactory.createBeverage(num);
// 獲得麻辣雞腿漢堡
ChinaHamburg hamburg = kfcFactory.createHamburg(num);
s[4]=("--套餐一,\t單價(jià):21,\t數(shù)量:"+num+"\t\t合計(jì):"+(beverage.totalPrice()+hamburg.totalPrice())+"\n");
System.out.print("--套餐一,\t單價(jià):21,\t數(shù)量:"+num+"\t\t合計(jì):"+(beverage.totalPrice()+hamburg.totalPrice())+"\n");
return beverage.totalPrice()+hamburg.totalPrice();
}
}
MainApp:
package xtx.factory.itf;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import xtx.IKfcFactory;
import xtx.factory.custom.Customer;
public class MainApp
{
/**
* 主應(yīng)用程序方法
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
/**
* 定義一個(gè)肯德基(IKfcFactory類型)
*/
IKfcFactory kfcFactory = (IKfcFactory) new ChinaKfcFactory();
Customer customer = new Customer(kfcFactory);
/**
* 開(kāi)始點(diǎn)餐
*/
// 一個(gè)麻辣雞腿漢堡
Scanner in =new Scanner(System.in);
//System.out.print("請(qǐng)輸入付款金額");
System.out.print("-----現(xiàn)有如下產(chǎn)品-----\n");
System.out.print("--麻辣風(fēng)味漢堡\t單價(jià):15.0.\n--奧爾良風(fēng)味雞翅\t單價(jià):3.0\n--普通風(fēng)味薯?xiàng)l\t單價(jià):8.0\n--可樂(lè)飲料\t單價(jià):6.0\n--套餐一(麻辣風(fēng)味漢堡+可樂(lè)飲料)\t單價(jià):21\n");
System.out.print("\n-----------------------");
System.out.print("\n請(qǐng)點(diǎn)餐:\n");
System.out.print("請(qǐng)輸入麻辣風(fēng)味漢堡數(shù)量---:");
int a1=in.nextInt();
System.out.print("請(qǐng)輸入奧爾良風(fēng)味雞翅數(shù)量-:");
int a2=in.nextInt();
System.out.print("普通入風(fēng)味薯?xiàng)l數(shù)量------:");
int a3=in.nextInt();
System.out.print("請(qǐng)輸入可樂(lè)飲料數(shù)量------:");
int a4=in.nextInt();
System.out.print("請(qǐng)輸入套餐份數(shù)---------:");
int a5=in.nextInt();
System.out.print("\n------賬單如下-----\n");
float hamhurgMoney = customer.orderHamburg(a1);
// 四個(gè)奧爾良烤雞翅
float chickenWingsMoney = customer.orderChickenWings(a2);
// 一包薯?xiàng)l
float frenchFriesMoney = customer.orderFrenchFries(a3);
// 兩杯可樂(lè)
float beverageMoney = customer.orderBeverage(a4);
float combo1=customer.ordercombo1(a5);
//
float sum=hamhurgMoney + chickenWingsMoney + frenchFriesMoney + beverageMoney+combo1;
customer.showbill();
System.out.println("總計(jì):" + (sum));
System.out.print("請(qǐng)輸入付款金額:");
int a=in.nextInt();
System.out.print("找零:"+(a-sum));
customer.showbill();
BufferedWriter bw=new BufferedWriter(new FileWriter("D://workspace2Eclipse//xtx//src//xtx//factory//custom//show.txt",true));
bw.write("總計(jì): "+sum);
bw.newLine();
bw.write("付款:"+a);
bw.newLine();
float y=a-sum;
bw.write("找零:"+y);
bw.newLine();
bw.flush();
bw.close();
}
}
運(yùn)行結(jié)果展示:

文件存儲(chǔ):

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java前后端分離的在線點(diǎn)餐系統(tǒng)實(shí)現(xiàn)詳解
- Java 實(shí)戰(zhàn)項(xiàng)目之在線點(diǎn)餐系統(tǒng)的實(shí)現(xiàn)流程
- Java 實(shí)戰(zhàn)項(xiàng)目之在線點(diǎn)餐系統(tǒng)的實(shí)現(xiàn)流程
- Java Swing實(shí)現(xiàn)餐廳點(diǎn)餐系統(tǒng)源碼(收藏版)
- Java實(shí)現(xiàn)餐廳點(diǎn)餐系統(tǒng)的實(shí)例代碼
- java實(shí)現(xiàn)可視化界面肯德基(KFC)點(diǎn)餐系統(tǒng)代碼實(shí)例
- java實(shí)現(xiàn)KFC點(diǎn)餐系統(tǒng)
- Java實(shí)現(xiàn)簡(jiǎn)單點(diǎn)餐系統(tǒng)
相關(guān)文章
關(guān)于@DS注解切換數(shù)據(jù)源失敗的原因?qū)崙?zhàn)記錄
項(xiàng)目配置了多個(gè)數(shù)據(jù)源,需要使用@DS注解來(lái)切換數(shù)據(jù)源,但是卻遇到了問(wèn)題,下面這篇文章主要給大家介紹了關(guān)于@DS注解切換數(shù)據(jù)源失敗原因的相關(guān)資料,需要的朋友可以參考下2023-05-05
基于Spring Boot DevTools實(shí)現(xiàn)開(kāi)發(fā)過(guò)程優(yōu)化
這篇文章主要介紹了基于Spring Boot DevTools實(shí)現(xiàn)開(kāi)發(fā)過(guò)程優(yōu)化,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
spring boot 配置動(dòng)態(tài)刷新實(shí)現(xiàn)詳解
這篇文章主要介紹了spring boot 配置動(dòng)態(tài)刷新實(shí)現(xiàn)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
詳解SpringBoot配置devtools實(shí)現(xiàn)熱部署
本篇文章主要介紹了詳解SpringBoot配置devtools實(shí)現(xiàn)熱部署 ,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05
Spring代理對(duì)象導(dǎo)致的獲取不到原生對(duì)象注解的解決
本文主要介紹了Spring代理對(duì)象導(dǎo)致的獲取不到原生對(duì)象注解的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
springboot+hutool批量生成二維碼壓縮導(dǎo)出功能
這篇文章主要介紹了springboot+hutool批量生成二維碼壓縮導(dǎo)出功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-10-10
一個(gè)例子帶你看懂Java中synchronized關(guān)鍵字到底怎么用
synchronized是Java里的一個(gè)關(guān)鍵字,起到的一個(gè)效果是"監(jiān)視器鎖",它的功能就是保證操作的原子性,同時(shí)禁止指令重排序和保證內(nèi)存的可見(jiàn)性,下面這篇文章主要給大家介紹了關(guān)于如何通過(guò)一個(gè)例子帶你看懂Java中synchronized關(guān)鍵字到底怎么用的相關(guān)資料,需要的朋友可以參考下2022-10-10
java代碼實(shí)現(xiàn)斗地主發(fā)牌功能
這篇文章主要介紹了java實(shí)現(xiàn)斗地主發(fā)牌功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11

