• 吃货联盟订餐系统


      1 package com.eat;
      2 
      3 import java.util.Scanner;
      4 
      5 public class EatSystem {
      6     public static void main(String[] args) {
      7         Scanner sc = new Scanner(System.in);
      8         System.out.println("欢迎使用“吃货联盟订餐系统”");
      9         String choose = "";//菜单选择的变量
     10         //初始化数据
     11         int length = 5;
     12         String[] names = new String[length];//订餐人
     13         String[] descs = new String[length];//订单餐品信息
     14         int[] dates =new int[length];//送餐日期
     15         String[] addresses = new String[length];//送餐地址
     16         double[] moneys = new double[length];//总价
     17         boolean[] status = new boolean[length];//订餐状态:true:完成;false未完成
     18         int[] nums = new int[length];//订餐数量
     19         double[] prices = new double[10];//单价
     20         String[] foods = new String[10];//菜品信息
     21         int[] zan = new int[10];//点赞数量
     22         zan[0] = 12;zan[2] = 5;zan[4]=25;
     23         foods[0] = "黄焖鸡";foods[1] = "东坡肉";foods[2] = "蛋炒饭";foods[3] = "北京烤鸭";foods[4] = "大肘子";
     24         prices[0] = 16.0;prices[1] = 15.5;prices[2] = 8.0;prices[3] = 49.9;prices[4] = 18.8;
     25         //初始化两条信息
     26         names[0] = "张三";
     27         descs[0] = "黄焖鸡";
     28         nums[0] = 2;
     29         moneys[0] = 32.0;
     30         dates[0] = 7;
     31         addresses[0] = "北京路18号";
     32         status[0] = true;
     33 
     34         names[1] = "李四";
     35         descs[1] = "东坡肉";
     36         nums[1] = 3;
     37         moneys[1] = 46.5;
     38         dates[1] = 8;
     39         addresses[1] = "北京路18号";
     40         status[1] = false;
     41 
     42         do {
     43             System.out.println("******************************");
     44             System.out.println("1、我要订餐  2、查看餐袋  3、签收订单  4、删除订单  5、我要点赞  6、退出系统");
     45             System.out.println("请选择:");
     46             choose = sc.next();
     47             switch (choose) {
     48             case "1":
     49                 System.out.println("****我要订餐****");
     50                 int index = -1;//定义要添加的位置下标
     51                 for(int i = 0 ;i<length;i++) {
     52                     if(names[i]==null) {
     53                         index = i;//将第一个为空的数组值i赋值给index;
     54                         break;
     55                     }
     56                 }
     57                 if(index<0) {//没有找到为空的数组值,
     58                     System.out.println("当前餐袋已满!!!");
     59                 }else {
     60                     System.out.println("请输入订餐人姓名:");
     61                     names[index] = sc.next();
     62                     System.out.println("序号	菜名	单价	点赞数量");
     63                     int max = foods.length;
     64                     for(int i = 0;i<foods.length;i++) {
     65                         if(foods[i]==null) {
     66                             max = i;
     67                             break;
     68                         }
     69                         System.out.println((i+1)+"	"+foods[i]+"	"+prices[i]+"元	"+zan[i]+"次");
     70                     }
     71                     System.out.println("请选择您要点的菜品编号:");
     72                     int id = 0;
     73                     do {
     74                         id = sc.nextInt();
     75                         if(id<1||id>max) {
     76                             System.out.println("不存在此编号菜品,请重新输入:");
     77                         }
     78                     } while (id<1||id>max);
     79                     descs[index] = foods[id-1];
     80                     System.out.println("请选择您需要的份数:");
     81                     int num = sc.nextInt();
     82                     nums[index] = num;
     83                     System.out.println("请输入送餐时间(送餐时间是10点至20点间整点送餐)");
     84                     int date = 0;
     85                     do {
     86                         date = sc.nextInt();
     87                         if(date<10||date>20) {
     88                             System.out.println("您的输入有误,请输入10~20间的整数!:");
     89                         }
     90                     } while (date<10||date>20);
     91                     dates[index] = date;
     92                     System.out.println("请输入送餐地址:");
     93                     addresses[index] = sc.next();
     94                     double money = prices[id-1]*num;
     95                     System.out.println("订餐成功:");
     96                     System.out.println("您订的是:"+foods[id-1]+" "+num+"份");
     97                     System.out.println("送餐时间:"+date+"点");
     98                     double song = 0.0;
     99                     if(money<20) {
    100                         song = 3.0;
    101                     }
    102                     moneys[index] = money+song;
    103                     System.out.println("餐费:"+money+"。送餐费:"+song+"元,总计:"+(money+song)+"元");
    104                 }
    105 
    106                 break;
    107             case "2":
    108                 System.out.println("****查看餐袋****");
    109                 System.out.println("序号	订餐人	餐品信息		送餐日期		送餐地址		总金额	订单状态");
    110                 for(int i = 0;i<length;i++) {
    111                     if(names[i]==null) {
    112                         break;
    113                     }
    114                     String canpin = descs[i]+" "+nums[i]+"份";
    115                     String zhuangtai = status[i]?"已完成":"已预订";
    116                     System.out.println((i+1)+"	"+names[i]+"	"+canpin+"	"+dates[i]+"点		"+addresses[i]+"		"+moneys[i]+"元	"+zhuangtai);
    117                 }
    118                 break;
    119             case "3":
    120                 System.out.println("****签收订单****");
    121                 System.out.println("请输入要签收的订单编号:");
    122                 boolean isTrue = false;
    123                 int id = -1;
    124                 do {
    125                     id = sc.nextInt();
    126                     if(id<1||id>descs.length) {
    127                         isTrue = true;
    128                     }else {
    129                         if(descs[id-1]==null) {
    130                             isTrue = true;
    131                         }else {
    132                             isTrue = false;
    133                         }
    134                     }
    135 
    136                     if(isTrue) {
    137                         System.out.println("不存在此编号的订单信息,请重新输入:");
    138                     }
    139                 } while (isTrue);
    140                 status[id-1] = true;
    141                 System.out.println("签收完成");
    142                 break;
    143             case "4":
    144                 System.out.println("****删除订单****");
    145                 System.out.println("请输入要删除的订单编号:");
    146                 int big = length;
    147                 for(int i = 0;i<length;i++) {
    148                     if(descs[i]==null) {
    149                         big = i;
    150                         break;
    151                     }
    152                 }
    153 
    154                 int no = 0;
    155                 do {
    156                     no = sc.nextInt();
    157                     if(no<1||no>big) {
    158                         System.out.println("不存在此编号菜品,请重新输入:");
    159                     }
    160                 } while (no<1||no>big);
    161 
    162                 if(status[no-1]==false) {
    163                     System.out.println("订单未完成,不能删除");
    164                 }else {
    165                     for(int i=no-1;i<length-1;i++) {
    166                         names[i] = names[i+1];
    167                         descs[i] = descs[i+1];
    168                         nums[i] = nums[i+1];
    169                         dates[i] = dates[i+1];
    170                         addresses[i] = addresses[i+1];
    171                         moneys[i] = moneys[i+1];
    172                         status[i] = status[i+1];
    173                     }
    174                     names[length-1] = null;
    175                     descs[length-1] = null;
    176                     nums[length-1] = 0;
    177                     dates[length-1] = 0;
    178                     addresses[length-1] = null;
    179                     moneys[length-1] = 0.0;
    180                     status[length-1] = false;
    181                     System.out.println("删除订单成功");
    182                 }
    183 
    184                 break;
    185             case "5":
    186                 System.out.println("****我要点赞****");
    187                 System.out.println("序号	菜名	单价	点赞数量");
    188                 int max = foods.length;
    189                 for(int i = 0;i<foods.length;i++) {
    190                     if(foods[i]==null) {
    191                         max = i;
    192                         break;
    193                     }
    194                     System.out.println((i+1)+"	"+foods[i]+"	"+prices[i]+"元	"+zan[i]+"次");
    195                 }
    196                 System.out.println("请选择您要点赞的菜品编号:");
    197                 int bianhao = 0;
    198                 do {
    199                     bianhao = sc.nextInt();
    200                     if(bianhao<1||bianhao>max) {
    201                         System.out.println("不存在此编号菜品,请重新输入:");
    202                     }
    203                 } while (bianhao<1||bianhao>max);
    204                 zan[bianhao-1]++;
    205                 System.out.println("点赞成功,谢谢您的反馈");
    206                 break;
    207             case "6":
    208                 System.out.println("****退出系统****");
    209                 System.out.println("谢谢使用");
    210                 break;
    211 
    212             default:
    213                 System.out.println("选择错误,请重新选择:");
    214                 choose = sc.next();
    215                 break;
    216             }
    217         }while(!"6".equals(choose));
    218     }
    219 }

    基础知识综合运用

  • 相关阅读:
    Create方法失效而没有提示错误信息
    JS弹出窗口控制
    本周活动
    JavaScript的初步了解
    关于PHP接收文件的资料
    mvc模式改进网站结构
    一周动态
    排序
    Java的内存泄漏
    Android笔记
  • 原文地址:https://www.cnblogs.com/Zhangchuanfeng1/p/10240589.html
Copyright © 2020-2023  润新知