最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實現(xiàn)KFC點餐系統(tǒng)

 更新時間:2019年01月24日 11:01:01   作者:xyj---  
這篇文章主要為大家詳細介紹了java實現(xiàn)KFC點餐系統(tǒng),模擬肯德基快餐店的收銀系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下

同學(xué)們應(yīng)該都去麥當勞或肯德基吃過快餐吧?請同學(xué)們參考肯德基官網(wǎng)的信息模擬肯德基快餐店的收銀系統(tǒng),合理使用C++/python/Java,結(jié)合設(shè)計模式(2種以上)至少實現(xiàn)系統(tǒng)的以下功能:

1.正常餐品結(jié)算和找零。
2.基本套餐結(jié)算和找零。
3.使用優(yōu)惠劵購買餐品結(jié)算和找零。
4.可在一定時間段參與店內(nèi)活動(自行設(shè)計或參考官網(wǎng)信息)。
5.模擬打印小票的功能(寫到文件中)。

類圖:

建立IFood接口實現(xiàn)各類食物信息的打?。?/p>

public interface IFood {
 /**
 * 打印輸出食物信息
 * @return 
 */
 String printMesage();

}

抽象類AbstractBaseFood

public class AbstractBaseFood {
 // 類別
 protected String kind;
 // 數(shù)量
 protected int num;
 // 價格
 protected float price;
 //找零
 // 合計
 public float totalPrice()
 {
 return this.num * this.price;
 }
 
}

各類果汁的基類Baverage:

public abstract class Beverage extends AbstractBaseFood implements IFood
{

 public String printMesage()
 {
 return ("--" + this.kind + "飲料,\t單價:" + this.price + ",\t數(shù)量:" + this.num + ",\t合計:" + this.totalPrice());
 }
}

建立Baverage的具體實現(xiàn)類ChinaBaverage:

public class ChinaBeverage extends Beverage
{

 public ChinaBeverage(int num)
 {
 this.kind = "可樂";
 this.price = 6.0f;
 this.num = num;
 }
}

以此類推分別建立 ChickenWing,F(xiàn)renchFries,Hamburg抽象類和它們的實現(xiàn)類ChinaChickenWing,FrenchFries,Hamburg

建立抽象工廠IKfcFactory:

public interface IKfcFactory
{
 // 生產(chǎn)漢堡
 public ChinaHamburg createHamburg(int num);

 // 生產(chǎn)薯條
 public xtx.FrenchFries createFrenchFries(int num);

 // 生產(chǎn)雞翅
 public ChinaChickenWings createChickenWings(int num);

 // 生產(chǎn)飲料
 public ChinaBeverage createBeverage(int num);
}

建立IKfcFactory的實現(xiàn)類ChinaFactory:

public class ChinaKfcFactory implements IKfcFactory
{
 // 生產(chǎn)可樂
 public ChinaBeverage createBeverage(int num)
 {
 return new ChinaBeverage(num);
 }
 // 生產(chǎn)奧爾良烤雞翅
 public ChinaChickenWings createChickenWings(int num)
 {
 return new ChinaChickenWings(num);
 }

 // 生產(chǎn)薯條
 public ChinaFrenchFries createFrenchFries(int num)
 {
 return new ChinaFrenchFries(num);
 }

 // 生產(chǎn)麻辣風(fēng)味雞腿漢堡
 public ChinaHamburg createHamburg(int num)
 {
 return new ChinaHamburg(num);
 }

}

建立Customer類實現(xiàn)食物的選擇和文件存儲:

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;
 }
 /**
 * 訂購食物
 * @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();
 }
 }
 // 訂購麻辣雞腿漢堡
 public float orderHamburg(int num) throws IOException 
 {
 // 獲得麻辣雞腿漢堡
 ChinaHamburg hamburg = kfcFactory.createHamburg(num);
 // 輸出訂購信息
 System.out.print(hamburg.printMesage());
 s[0]=hamburg.printMesage();
 System.out.print("\n");
 // 返回總價
 return hamburg.totalPrice();
 }
 // 訂購奧爾良烤雞翅
 public float orderChickenWings(int num)
 {
 // 獲得奧爾良烤雞翅
 ChinaChickenWings chickenWings = kfcFactory.createChickenWings(num);
 // 輸出訂購信息
 System.out.print(chickenWings.printMesage());
 s[1]=chickenWings.printMesage();
 System.out.print("\n");
 // 返回總價
 return chickenWings.totalPrice();
 }
 // 訂購薯條
 public float orderFrenchFries(int num) 
 {
 // 獲得薯條
 ChinaFrenchFries frenchFries = (ChinaFrenchFries) ((IKfcFactory) kfcFactory).createFrenchFries(num);
 // 輸出訂購信息
 System.out.print(frenchFries.printMesage());
 s[2]=frenchFries.printMesage();
 System.out.print("\n");
 // 返回總價
 return frenchFries.totalPrice();
 }
 // 訂購可樂
 public float orderBeverage(int num) 
 {
 // 獲得可樂
 ChinaBeverage beverage = kfcFactory.createBeverage(num);
 // 輸出訂購信息
 System.out.print(beverage.printMesage());
 s[3]=beverage.printMesage();
 System.out.print("\n");
 return beverage.totalPrice();
 }
 //訂購套餐一
 public float ordercombo1(int num)
 {
 // 獲得可樂
 ChinaBeverage beverage = kfcFactory.createBeverage(num);
 // 獲得麻辣雞腿漢堡
 ChinaHamburg hamburg = kfcFactory.createHamburg(num);
 s[4]=("--套餐一,\t單價:21,\t數(shù)量:"+num+"\t\t合計:"+(beverage.totalPrice()+hamburg.totalPrice())+"\n");
 System.out.print("--套餐一,\t單價:21,\t數(shù)量:"+num+"\t\t合計:"+(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 
 {
 /**
 * 定義一個肯德基(IKfcFactory類型)
 */
 IKfcFactory kfcFactory = (IKfcFactory) new ChinaKfcFactory();
 Customer customer = new Customer(kfcFactory);
 /**
 * 開始點餐
 */
 // 一個麻辣雞腿漢堡
 Scanner in =new Scanner(System.in);
 //System.out.print("請輸入付款金額");
 System.out.print("-----現(xiàn)有如下產(chǎn)品-----\n");
 System.out.print("--麻辣風(fēng)味漢堡\t單價:15.0.\n--奧爾良風(fēng)味雞翅\t單價:3.0\n--普通風(fēng)味薯條\t單價:8.0\n--可樂飲料\t單價:6.0\n--套餐一(麻辣風(fēng)味漢堡+可樂飲料)\t單價:21\n");
 System.out.print("\n-----------------------");
 System.out.print("\n請點餐:\n");
 System.out.print("請輸入麻辣風(fēng)味漢堡數(shù)量---:");
 int a1=in.nextInt();
 System.out.print("請輸入奧爾良風(fēng)味雞翅數(shù)量-:");
 int a2=in.nextInt();
 System.out.print("普通入風(fēng)味薯條數(shù)量------:");
 int a3=in.nextInt();
 System.out.print("請輸入可樂飲料數(shù)量------:");
 int a4=in.nextInt();
 System.out.print("請輸入套餐份數(shù)---------:");
 int a5=in.nextInt();
 System.out.print("\n------賬單如下-----\n");
 float hamhurgMoney = customer.orderHamburg(a1);
 // 四個奧爾良烤雞翅 
 float chickenWingsMoney = customer.orderChickenWings(a2);
 // 一包薯條
 float frenchFriesMoney = customer.orderFrenchFries(a3);
 // 兩杯可樂
 float beverageMoney = customer.orderBeverage(a4);
 float combo1=customer.ordercombo1(a5);
 //
 float sum=hamhurgMoney + chickenWingsMoney + frenchFriesMoney + beverageMoney+combo1;
 customer.showbill();
 System.out.println("總計:" + (sum));
 System.out.print("請輸入付款金額:");
 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("總計: "+sum);
 bw.newLine();
 bw.write("付款:"+a);
 bw.newLine();
 float y=a-sum;
 bw.write("找零:"+y);
 bw.newLine();
 bw.flush();
 bw.close();
 }
}

運行結(jié)果展示:

文件存儲:

更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java循環(huán)終止的實現(xiàn)方式總結(jié)

    Java循環(huán)終止的實現(xiàn)方式總結(jié)

    循環(huán)是一種重復(fù)執(zhí)行一段代碼的結(jié)構(gòu),Java提供了四種主要的循環(huán)結(jié)構(gòu),本文主要來和大家介紹一下Java循環(huán)終止的實現(xiàn)方式,有需要的小伙伴可以參考一下
    2023-10-10
  • Spring Boot動態(tài)加載Jar包與動態(tài)配置實現(xiàn)

    Spring Boot動態(tài)加載Jar包與動態(tài)配置實現(xiàn)

    隨著項目的不斷演進和業(yè)務(wù)需求的增長,很多場景下需要實現(xiàn)系統(tǒng)的動態(tài)性和靈活性,本文主要介紹了Spring Boot動態(tài)加載Jar包與動態(tài)配置實現(xiàn),具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • java如何連接數(shù)據(jù)庫executeUpdate()和executeQuery()

    java如何連接數(shù)據(jù)庫executeUpdate()和executeQuery()

    這篇文章主要介紹了java如何連接數(shù)據(jù)庫executeUpdate()和executeQuery(),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 基于synchronized修飾靜態(tài)和非靜態(tài)方法

    基于synchronized修飾靜態(tài)和非靜態(tài)方法

    這篇文章主要介紹了基于synchronized修飾靜態(tài)和非靜態(tài)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-04-04
  • java 中二分法查找的應(yīng)用實例

    java 中二分法查找的應(yīng)用實例

    這篇文章主要介紹了java 中二分法查找的應(yīng)用實例的相關(guān)資料,希望通過本文大家能掌握二分法的使用方法,需要的朋友可以參考下
    2017-09-09
  • 聊聊finally中的代碼一定會執(zhí)行嗎

    聊聊finally中的代碼一定會執(zhí)行嗎

    通常在面試中,只要是疑問句一般答案都是“否定”的,因為如果是“確定”和“正?!钡?那面試官就沒有必要再問了嘛,本文想和大家聊聊finally中的代碼一定會執(zhí)行嗎?,感興趣的朋友跟著小編一起來看看吧
    2023-12-12
  • Java如何利用Easyexcel動態(tài)導(dǎo)出表頭列

    Java如何利用Easyexcel動態(tài)導(dǎo)出表頭列

    這篇文章主要介紹了Java利用Easyexcel動態(tài)導(dǎo)出表頭列的實例,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • springboot+vue實現(xiàn)SSE服務(wù)器發(fā)送事件的示例

    springboot+vue實現(xiàn)SSE服務(wù)器發(fā)送事件的示例

    本文介紹了使用Spring Boot和Vue實現(xiàn)服務(wù)器發(fā)送事件,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-01-01
  • 用java等語言仿360首頁拼音輸入全模糊搜索和自動換膚

    用java等語言仿360首頁拼音輸入全模糊搜索和自動換膚

    這篇文章主要為大家詳細介紹了仿360首頁支持拼音輸入全模糊搜索和自動換膚的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • idea中g(shù)it如何修改commit(ChangeList的使用)

    idea中g(shù)it如何修改commit(ChangeList的使用)

    這篇文章主要介紹了idea中g(shù)it如何修改commit(ChangeList的使用),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04

最新評論

雅安市| 台南市| 务川| 航空| 韶山市| 丰城市| 清原| 灵山县| 平罗县| 嘉鱼县| 民丰县| 阜宁县| 栾川县| 海丰县| 滁州市| 永靖县| 涞源县| 司法| 从江县| 探索| 鄂托克旗| 盐山县| 余干县| 伊金霍洛旗| 浦城县| 五河县| 江孜县| 丰顺县| 迁安市| 南召县| 留坝县| 广安市| 丰原市| 彰化市| 那曲县| 赞皇县| 伊吾县| 海宁市| 岐山县| 枣阳市| 峡江县|