一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - java實現KFC點餐系統

java實現KFC點餐系統

2021-07-12 14:58xyj--- Java教程

這篇文章主要為大家詳細介紹了java實現KFC點餐系統,模擬肯德基快餐店的收銀系統,具有一定的參考價值,感興趣的小伙伴們可以參考一下

同學們應該都去麥當勞或肯德基吃過快餐吧?請同學們參考肯德基官網的信息模擬肯德基快餐店的收銀系統,合理使用c++/python/java,結合設計模式(2種以上)至少實現系統的以下功能:

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

類圖:

java實現KFC點餐系統

建立ifood接口實現各類食物信息的打印:

?
1
2
3
4
5
6
7
8
public interface ifood {
 /**
 * 打印輸出食物信息
 * @return
 */
 string printmesage();
 
}

抽象類abstractbasefood

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class abstractbasefood {
 // 類別
 protected string kind;
 // 數量
 protected int num;
 // 價格
 protected float price;
 //找零
 // 合計
 public float totalprice()
 {
 return this.num * this.price;
 }
 
}

各類果汁的基類baverage:

?
1
2
3
4
5
6
7
8
public abstract class beverage extends abstractbasefood implements ifood
{
 
 public string printmesage()
 {
 return ("--" + this.kind + "飲料,\t單價:" + this.price + ",\t數量:" + this.num + ",\t合計:" + this.totalprice());
 }
}

建立baverage的具體實現類chinabaverage:

?
1
2
3
4
5
6
7
8
9
10
public class chinabeverage extends beverage
{
 
 public chinabeverage(int num)
 {
 this.kind = "可樂";
 this.price = 6.0f;
 this.num = num;
 }
}

以此類推分別建立 chickenwing,frenchfries,hamburg抽象類和它們的實現類chinachickenwing,frenchfries,hamburg

建立抽象工廠ikfcfactory:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public interface ikfcfactory
{
 // 生產漢堡
 public chinahamburg createhamburg(int num);
 
 // 生產薯條
 public xtx.frenchfries createfrenchfries(int num);
 
 // 生產雞翅
 public chinachickenwings createchickenwings(int num);
 
 // 生產飲料
 public chinabeverage createbeverage(int num);
}

建立ikfcfactory的實現類chinafactory:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class chinakfcfactory implements ikfcfactory
{
 // 生產可樂
 public chinabeverage createbeverage(int num)
 {
 return new chinabeverage(num);
 }
 // 生產奧爾良烤雞翅
 public chinachickenwings createchickenwings(int num)
 {
 return new chinachickenwings(num);
 }
 
 // 生產薯條
 public chinafrenchfries createfrenchfries(int num)
 {
 return new chinafrenchfries(num);
 }
 
 // 生產麻辣風味雞腿漢堡
 public chinahamburg createhamburg(int num)
 {
 return new chinahamburg(num);
 }
 
}

建立customer類實現食物的選擇和文件存儲:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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;
 // 構造方法將抽象工廠作為參數傳入
 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數量:"+num+"\t\t合計:"+(beverage.totalprice()+hamburg.totalprice())+"\n");
 system.out.print("--套餐一,\t單價:21,\t數量:"+num+"\t\t合計:"+(beverage.totalprice()+hamburg.totalprice())+"\n");
 return beverage.totalprice()+hamburg.totalprice();
 }
}

mainapp:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
{
 /**
 * 主應用程序方法
 *
 * @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("-----現有如下產品-----\n");
 system.out.print("--麻辣風味漢堡\t單價:15.0.\n--奧爾良風味雞翅\t單價:3.0\n--普通風味薯條\t單價:8.0\n--可樂飲料\t單價:6.0\n--套餐一(麻辣風味漢堡+可樂飲料)\t單價:21\n");
 system.out.print("\n-----------------------");
 system.out.print("\n請點餐:\n");
 system.out.print("請輸入麻辣風味漢堡數量---:");
 int a1=in.nextint();
 system.out.print("請輸入奧爾良風味雞翅數量-:");
 int a2=in.nextint();
 system.out.print("普通入風味薯條數量------:");
 int a3=in.nextint();
 system.out.print("請輸入可樂飲料數量------:");
 int a4=in.nextint();
 system.out.print("請輸入套餐份數---------:");
 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();
 }
}

運行結果展示:

java實現KFC點餐系統

文件存儲:

java實現KFC點餐系統

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/Mr__Cat_/article/details/83448749

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 性派对videos18party| 男男playh片在线观看 | 国产区1| 国产日韩精品一区二区三区 | 日本高清色视影www日本 | 欧美成人午夜片一一在线观看 | 免费高清特黄a 大片 | 第一福利在线导航 | 天天做天天爱天天综合网 | 星空无限传媒xk8027穆娜 | 87影院在线观看视频在线观看 | 亚洲欧美优优色在线影院 | 99精品网站| 午夜福利试看120秒体验区 | 99热视| 97青草香蕉依人在线播放 | 喷奶水榨乳ova动漫无修 | 国产高清不卡视频在线播放 | 深夜影院a| 日本黄色影院 | 日本捏胸吃奶视频免费 | 久久久久久久久人体 | 97久久久亚洲综合久久88 | 精品一区二区国语对白 | chinese帅男gay野外性 | 暖暖 免费 高清 日本 中文 | 精品久久香蕉国产线看观看亚洲 | 好姑娘在线视频观看免费 | 桥本有菜ssni-677在线观看 | 韩国美女豪爽一级毛片 | 日本一本二本三区免费 | 亚洲另类激情 | 五月天91 | 日韩香蕉网 | nhdta系列媚药系列 | 国产精品视频一区二区三区经 | 亚洲男人的天堂成人 | 久久精品午夜一区二区福利 | 国产精品亚洲午夜不卡 | 男男双性生子产乳高辣h | 日本大巴车强thepro |