吃货联盟订餐系统(二)
生活随笔
收集整理的這篇文章主要介紹了
吃货联盟订餐系统(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
---恢復內容開始---
1 import java.util.Scanner;
2
3 /**
4 * 菜單
5 * @author 99573
6 *
7 */
8 public class Muen {
//第一步先實例化兩個初始化訂餐的對象,以及聲明一個成員變量的編號
9 Scanner sc = new Scanner(System.in);
10 OrderingSet a = new OrderingSet();
11 OrderingUtil b = new OrderingUtil();
12 int bianhao;
13 /**
14 * 初始化變量
15 */
16 public void ini(){
17 a.ini();
18 b.ini();
19 }
20 /**
21 * 返回 上一層代碼
22 */
23 public void re(){
24 System.out.println("輸入0返回上一層");
25 String isfhui = sc.next();
26 if (isfhui.equals("0")) {
27 initMuen();
28 }
29 }
30 public void initMuen(){
31 System.out.println("歡迎使用”吃貨聯盟訂餐系統“");
32 System.out.println("*********************************");
33 System.out.println("1、我要訂餐");
34 System.out.println("2、查看餐袋");
35 System.out.println("3、簽收訂單");
36 System.out.println("4、刪除訂單");
37 System.out.println("5、我要點贊");
38 System.out.println("6、退出系統");
39 System.out.println("*********************************");
40 System.out.println("選擇:");
41 bianhao = sc.nextInt();
42 switch (bianhao) {
43 case 1:
44 orderMuen();
45 break;
46 case 2:
47 show();
48 re();
49 break;
50 case 3:
51 State();
52 break;
53 case 4:
54 delete();
55 break;
56 case 5:
57 good();
58 break;
59 case 6:
60 end();
61 break;
62
63 default:
64 System.out.println("輸入錯誤!");
65 initMuen();
66 break;
67 }
68 }
69 /**
70 * 訂餐菜單
71 */
72 public void orderMuen(){
73 int index =0;
74 for (int j = 0; j < a.order.length; j++) {
75 if (a.order[j].Number == 0) {
76 index = j;
77 break;
78 }
79 }
80 if(index <4){
81
82 System.out.println("我要訂餐:");
83 System.out.println("輸入訂餐人名:");
84 a.order[index].name = sc.next();
85 System.out.println("編號 菜名 單價 點贊數");
86 for (int i = 0; i < b.food.length; i++) {
87 System.out.println((i+1)+" "+b.food[i].name+" "+b.food[i].money+" "+b.food[i].goodNum);
88 System.out.println();
89 }
90 System.out.println("輸入你要定的菜的編號:");
91 int bianhao = sc.nextInt();
92 a.order[index].Dishes = b.food[bianhao-1].name;
93 System.out.println("輸入份數:");
94 a.order[index].Number = sc.nextInt();
95 System.out.println("送餐時間:");
96 a.order[index].Times = sc.next();
97 System.out.println("送餐地址:");
98 a.order[index].addresses = sc.next();
99 a.order[index].sumPrices =(a.order[index].Number*b.food[bianhao-1].money)>50?a.order[index].Number*b.food[bianhao-1].money:a.order[index].Number*b.food[bianhao-1].money+5;
100 System.out.println("訂餐成功!本次訂餐狀態如下:");
101 System.out.println("訂餐人"+" 菜品"+" 份數"+" 送餐時間"+" 送餐地點"+" 送餐總價");
102 System.out.println(a.order[index].name+" "+a.order[index].Dishes+" "+a.order[index].Number+" "+a.order[index].Times+" "+a.order[index].addresses+" "+a.order[index].sumPrices);
103 }else{
104 System.out.println("餐袋已滿!請刪除后在進行訂餐");
105 }
106 re();
107 }
108 /**
109 * 顯示餐袋
110 */
111 public void show(){
112 for (int i = 0; i < a.order.length; i++) {
113 if (a.order[i].name!=null) {
114
115 String States = a.order[i].States==1 ? "已簽收" : "未簽收";
116 System.out.printf("%10s%10s%10s%10s%10s%10s%10s%10s
",(i+1),a.order[i].name,
117 a.order[i].Dishes,a.order[i].Number,a.order[i].Times,
118 a.order[i].addresses,States,a.order[i].sumPrices);
119 System.out.println();
120 } else {
121 a.index = i;
122 break;
123 }
124 }
125 }
126 /**
127 * 簽收
128 * @param args
129 */
130
131 public void State(){
132 show();
133 System.out.println("輸入你要簽收的編號:");
134 bianhao = sc.nextInt();
135 int index = bianhao-1;
136 if (a.order[index].name!=null) {
137 if (a.order[index].States ==0) {
138 a.order[index].States = 1;
139 System.out.println("簽收成功!");
140 }else{
141 System.out.println("該訂單已簽收!請勿重復簽收");
142 }
143
144 } else {
145 System.out.println("該訂單不存在");
146 }
147 re();
148 }
149 /**
150 * 刪除方法
151 */
152
153 public void delete(){
154 show();
155 System.out.println("選擇你要刪除的訂餐編號:");
156 bianhao = sc.nextInt();
157 if(a.order[bianhao-1].name!=null){
158
159 if (a.order[0] != null) {
160 if (a.order[bianhao - 1].States == 1) {
161 for (int i = bianhao - 1; i < a.index; i++) {
162 a.order[i] = a.order[i + 1];
163 }
164 System.out.println("刪除成功!");
173 } else {
174 System.out.println("只能刪除以簽收的訂單!");
175 }
176 } else {
177 System.out.println("沒有可刪除的訂單!");
178 }
179 }else{
180 System.out.println("未找到要刪除的訂單!");
181 }
182 re();
183 }
184 /**
185 * 點贊
186 */
187 public void good(){
188 System.out.println("選擇你要點贊的的菜品:");
189 System.out.println(" 餐名 單價 點贊數");
190 for (int i = 0; i < b.food.length; i++) {
191 System.out.println((i+1)+" "+b.food[i].name+" "+b.food[i].money+" "+b.food[i].goodNum);
192 }
193 bianhao =sc.nextInt();
194 if (bianhao==1||bianhao==2||bianhao==3) {
195 int index = bianhao-1;
196 b.food[index].goodNum++;
197 System.out.println("點贊成功");
198 }else{
199 System.out.println("不存在該菜品,輸入錯誤點贊失敗!");
200 }
201 re();
202 }
203 /**
204 * 退出系統類
205 * @param args
206 */
207 public void end(){
208 System.out.println("退出系統,再見!");
209 }
210 public static void main(String[] args) {
211 Muen a = new Muen();
212 a.ini();
213 a.initMuen();
214 }
215
216 }
第一步 :運用ini方法進行數據的初始話,否則,餐袋將無 任何數據(主要就是執行兩個初始化信息類的初始化方法)
第二步:運用initMuen 來初始化菜單,將六個子菜單顯示出來, 用switch選擇結構來接受并跳轉到子菜單的方法里。
第三步:設置6個具體方法
訂餐方法主要的思路是首先設置了一個局部變量index代表下標 接下來遍歷整個訂餐信息數組,將下標鎖定在數據為空的數組對象上,然后進行判斷是否大于4個上限,如果不大于上限就進行下面的訂餐信息錄用否則的話,就提示餐袋已滿 。最后執行re方法,(re方法就是封裝在initMuen方法上的一個方法,主要作用就是返回到選擇菜單上)。
查看餐袋 很簡單就是先遍歷數組查看數組的信息,然后 將 信息不為空的數組的對象輸出出來。里面115行是一個三元表達式,主要判斷是否已簽收。
簽收訂單 這個就是把對象的States屬性的值改變 ,0為未簽收,1為簽收,不過首先要遍歷下數組,查看具體信息的個數,和判斷訂單是否簽收。簽收過的訂單不能重復簽收。
刪除訂單 主要思路 將選到的下標對象的下一個對象往前賦值,將原本數據進行前移。
點贊 主要思路就是找到訂餐信息的點贊屬性,進行不斷的累加
退出 就是結束整個程序
項目需求 :六個功能:訂餐 查看餐袋,簽收 刪除 和退出
訂餐不超過4個
總結
以上是生活随笔為你收集整理的吃货联盟订餐系统(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 涉嫌销售欺诈被集体起诉 高合车主自拆爱车
- 下一篇: 常用寄存器说明、汇编代码详解