吃货联盟订餐系统

Posted fkkkkk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了吃货联盟订餐系统相关的知识,希望对你有一定的参考价值。

 1 package com.Chihuo;
 2 /*
 3        吃货联盟订餐系统
 4  */
 5 import java.util.Scanner;
 6 public class ChiHuoLianMeng {
 7     public static void main(String[] args) {
 8         Dingcan dc = new Dingcan();
 9         Canpin cp = new Canpin();
10         Scanner sc = new Scanner(System.in);
11         int s1 = 0;
12 
13         dc.name[0] = "张三";
14         dc.canpin[0] = "鱼香肉丝 2份";
15         dc.dizhi[0] = "故公路15号";
16         dc.shijian[0] = 20;
17         dc.sum[0] = 46.0;
18         dc.zhuangtai[0] = 0;
19 
20         System.out.println("欢迎使用“吃货联盟订餐系统”");
21         do {
22             System.out.println("****************************");
23             System.out.println("1、我要订餐");
24             System.out.println("2、查看餐袋");
25             System.out.println("3、签收订单");
26             System.out.println("4、删除订单");
27             System.out.println("5、我要点赞");
28             System.out.println("6、退出系统");
29             System.out.println("****************************");
30             System.out.print("请选择:");
31             s1 = sc.nextInt();
32             switch (s1) {
33                 case 1:
34                     dc.dingcan();//调用订餐方法
35                     break;
36                 case 2:
37                     System.out.println("************查看餐袋*********");
38                     dc.chakan();//调用查看餐袋方法
39                     break;
40                 case 3:
41                     dc.chakan();
42                     dc.qianshou();
43                     break;
44                 case 4:
45                     dc.shanchu();
46                     break;
47                 case 5:
48                     dc.dianzan();
49                     break;
50                 case 6:
51                     break;
52             }
53             if (s1 < 0 || s1 > 5) {
54                 System.out.println("谢谢使用本系统");
55                 break;
56             }
57             System.out.print("输入0返回:");
58             s1 = sc.nextInt();
59             while (s1 != 0) {
60                 System.out.print("输入错误,请输入0返回:");
61                 s1 = sc.nextInt();
62             }
63         } while (s1 == 0);
64     }
65 }

 

 

类2

  1 package com.Chihuo;
  2 
  3 import java.util.Scanner;
  4 
  5 //订餐
  6 public class Dingcan {
  7     String name[] = new String[4];//姓名
  8     String canpin[] = new String[4];//餐品信息
  9     int shijian[] = new int[4];//日期
 10     String dizhi[] = new String[4];//地址
 11     double sum[] = new double[4];//总金额
 12     int zhuangtai[] = new int[4];//状态
 13 
 14     Scanner sc = new Scanner(System.in);
 15     Canpin cp = new Canpin();
 16 
 17 
 18     //方法
 19     //我要订餐
 20     public void dingcan() {
 21         //遍历数组,找到空的位置,记录下来
 22         boolean isnull = false;
 23         System.out.println("************我要订餐*********");
 24 
 25         for (int i = 0; i < name.length; i++) {
 26             if (name[i] == null) {
 27 
 28                 System.out.print("请输入订餐人姓名:");
 29                 String name1 = sc.next();
 30                 System.out.println("序号		菜名			单价		点赞数");
 31                 //循环输出菜单
 32                 for (int j = 0; j < cp.caiming.length; j++) {
 33                     System.out.println((j + 1) + "		" + cp.caiming[j] + "		" + cp.danjia[j] + "元		" + cp.dianzan[j]);
 34                 }
 35                 System.out.print("请选择要点的菜品编号:");
 36                 int bianhao = sc.nextInt();
 37                 while (bianhao < 0 || bianhao > cp.caiming.length) {
 38                     System.out.print("输入错误,请重新输入1-" + cp.caiming.length + ":");
 39                     bianhao = sc.nextInt();
 40                 }
 41                 System.out.print("请选择需要的份数");
 42                 int fenshu = sc.nextInt();
 43                 String canpin1 = cp.caiming[bianhao - 1] + " " + fenshu + "份";
 44                 System.out.print("请输入送餐时间10-20:");
 45                 int shijian1 = sc.nextInt();
 46                 while (shijian1 < 10 || shijian1 > 20) {
 47                     System.out.print("输入错误,请重新输入10-20:");
 48                     shijian1 = sc.nextInt();
 49                 }
 50                 System.out.print("请输入送餐地址:");
 51                 String dizhi1 = sc.next();
 52                 System.out.println("订餐成功!");
 53                 System.out.println("您订的是:" + canpin1);
 54                 System.out.println("送餐时间:" + shijian1 + "点");
 55                 double canfei = cp.danjia[bianhao - 1] * fenshu;
 56                 double songcanfei = canfei > 50 ? 0.0 : 6.0;
 57                 double sum1 = canfei + songcanfei;
 58                 System.out.println("餐费" + canfei + "元,配送费" + songcanfei + "元,总计" + sum1 + "元");
 59 
 60 
 61                 name[i] = name1;
 62                 canpin[i] = canpin1;
 63                 dizhi[i] = dizhi1;
 64                 shijian[i] = shijian1;
 65                 sum[i] = sum1;
 66                 zhuangtai[i] = 0;
 67 
 68                 isnull = true;
 69                 break;
 70             }
 71         }
 72         if (!isnull) {
 73             System.out.println("对不起,餐袋已满");
 74         }
 75     }
 76 
 77     //查看餐袋
 78     public void chakan() {
 79 
 80         System.out.println("序号		订餐人		餐品信息			送餐日期		送餐地址			总金额		订单状态");
 81         for (int i = 0; i < name.length; i++) {
 82             if (name[i] != null) {
 83                 String dizhi1 = dizhi[i];
 84                 double sum1 = sum[i];
 85                 String zhuangtai1 = zhuangtai[i] == 0 ? "已预定" : "已签收";
 86                 System.out.println((i + 1) + "		" + name[i] + "			" + canpin[i] + "		" + shijian[i] + "点			" + dizhi1 + "		" + sum1 + "元		" + zhuangtai1);
 87             } else {
 88                 break;
 89             }
 90         }
 91 
 92     }
 93 
 94     //订单签收
 95     public void qianshou() {
 96         System.out.println("************签收订单*********");
 97         System.out.print("请输入要签收的编号:");
 98         int bianhao = sc.nextInt();
 99         boolean isno1 = false;
100         for (int i = 0; i < name.length; i++) {
101             if (name[i] != null && zhuangtai[i] == 0 && bianhao == i + 1) {
102                 zhuangtai[i] = 1;
103                 System.out.println("订单签收成功");
104                 isno1 = true;
105                 break;
106             } else if (name[i] != null && zhuangtai[i] == 1 && bianhao == i + 1) {
107                 System.out.println("请勿重复签收订单");
108                 isno1 = true;
109                 break;
110             }
111             if (!isno1) {
112                 System.out.println("您输入的订单不存在");
113                 break;
114             }
115         }
116     }
117 
118     //删除订单
119     public void shanchu() {
120         System.out.println("************删除订单*********");
121         System.out.print("请输入要删除的编号:");
122         int bianhao = sc.nextInt();
123         boolean isno = false;
124         int xiabiao = -1;
125         //遍历记录要删除的下标
126         for (int i = 0; i < name.length; i++) {
127             if (name[i] != null && zhuangtai[i] == 1 && bianhao == i + 1) {
128                 xiabiao = i;
129                 isno = true;
130                 break;
131             } else if (name[i] != null && zhuangtai[i] == 0 && bianhao == i + 1) {
132                 System.out.println("你选择的订单未签收,不能删除");
133                 isno = true;
134                 break;
135             }
136         }
137         if (!isno) {
138             System.out.println("此订单不存在");
139         }
140         if (xiabiao != -1) {
141             for (int i = xiabiao + 1; i < name.length; i++) {
142                 name[i - 1] = name[i];
143                 canpin[i - 1] = canpin[i];
144                 shijian[i - 1] = shijian[i];
145                 dizhi[i - 1] = dizhi[i];
146                 sum[i - 1] = sum[i];
147                 zhuangtai[i - 1] = zhuangtai[i];
148             }
149 
150             name[name.length - 1] = null;
151             canpin[name.length - 1] = null;
152             shijian[name.length - 1] = 0;
153             dizhi[name.length - 1] = null;
154             sum[name.length - 1] = 0.0;
155             zhuangtai[name.length - 1] = 0;
156             System.out.println("订单删除成功");
157         }
158     }
159 
160     //我要点赞
161     public void dianzan() {
162         System.out.println("************我要点赞*********");
163         System.out.println("序号		菜名			单价		点赞数");
164         //循环输出菜单
165         for (int j = 0; j < cp.caiming.length; j++) {
166             System.out.println((j + 1) + "		" + cp.caiming[j] + "		" + cp.danjia[j] + "元		" + cp.dianzan[j]);
167         }
168         System.out.print("请选择要点赞的菜品编号:");
169         int bianhao = sc.nextInt();
170         while (bianhao < 0 || bianhao > cp.caiming.length) {
171             System.out.print("输入错误,请重新输入1-" + cp.caiming.length + ":");
172             bianhao = sc.nextInt();
173         }
174         cp.dianzan[bianhao - 1] += 1;
175         System.out.println("点赞成功!");
176     }
177 }

 

类3

1 package com.Chihuo;
2 //餐品信息
3 public class Canpin {
4     String caiming[]={"红烧带鱼","鱼香肉丝","时令鲜蔬"};//菜名
5     double danjia[]={38.0,20.0,10.0};//单价
6     int dianzan[]={10,30,0};
7 }

 

以上是关于吃货联盟订餐系统的主要内容,如果未能解决你的问题,请参考以下文章

吃货联盟订餐系统

吃货联盟订餐系统

第一个项目--------------吃货联盟订餐系统

第五章吃货联盟订餐系统

吃货联盟订餐系统(用对象和数组来写的)

小项目,吃货联盟,java初级小项目,源代码