zoukankan      html  css  js  c++  java
  • java基础之吃货联盟

    因为用的是普通数组,所以编写的代码可能比较长,而且有的功能还比较不健全,代码如下:

    0.定义数组(因为用static修饰可以不用New,比较方便,但可能比较损耗性能)

     1 //订餐人名字
     2     static String [] names=new String[10];
     3     //保存菜品
     4     static String [] sums=new String[10];
     5     //送餐时间
     6     static int [] times=new int[10];
     7     //地址
     8     static String [] addres =new String[10];
     9     //状态
    10     static int [] states= new int[10];  
    11     //总金额
    12     static double [] sumPrice=new double[10];
    13     //点赞
    14     static int [] upvote=new int[10];
    数组

    1.初始数据(因为没有用到数据库,所以只能用初始化数组)

     1 //初始化数据
     2     public static void  Inial() {
     3         sums[0]="油炸脚趾盖";
     4         sums[1]="红烧猪蹄";
     5         sums[2]="鱼香肉丝";
     6         
     7         sumPrice[0]=21.0;
     8         sumPrice[1]=10.0;
     9         sumPrice[2]=15;
    10         
    11         names[0]="本";
    12         names[1]="本庆";
    13         names[2]="我";
    14         
    15         addres[0]="推动软件";
    16         addres[1]="地狱火";
    17         addres[2]="五道口";
    18         
    19         states[0]=0;
    20         states[1]=0;
    21         states[2]=0;
    22         
    23         sumPrice[0]=21;
    24         sumPrice[1]=50;
    25         sumPrice[2]=15;
    26     }
    初始化数据

    2.主菜单

     1 public static void Menu() {
     2        
     3         
     4         System.out.println("1.我要订餐");
     5         System.out.println("2.查看餐袋");
     6         System.out.println("3.签收订单");
     7         System.out.println("4.删除订单");
     8         System.out.println("5.我要点赞");
     9         System.out.println("6.退出系统");
    10 
    11         System.out.println("请选择");
    12         String opterString=input.next();
    13         switch (opterString) {
    14         //订餐
    15         case "1":
    16             Dinner();
    17             break;
    18        //查看
    19         case "2":
    20             Show();
    21             break;
    22        //签收        
    23      case "3":
    24           Sign();
    25             break;
    26         //删除    
    27        case "4":
    28            delete();   
    29           break;
    30         //点赞  
    31     case "5":
    32         Upvote();
    33         break;
    34     case "6":
    35         Exit();
    36     break;
    37         default:
    38             System.out.println("没有该选项!!!");
    39             break;
    40         }
    41     }
    主菜单

    3.订餐(因为编号不存在的菜品,不能选择)

     1 //订餐
     2     public static void Dinner() {
     3       System.out.println("***菜品展示****");
     4       System.out.println("请输入订餐人");
     5       String name=input.next();
     6         System.out.println("序号"+"————————"+"菜品");
     7       for (int i = 0; i < sums.length; i++) {
     8         if (sums[i]!=null) {
     9             System.out.println(i+1+""+sums[i]);
    10         }
    11       }
    12       System.out.println("请输入您要点的菜品编号");
    13       int id=input.nextInt();
    14       id=id-1;
    15       //System.out.println(id);
    16       for (int j = 0; j < names.length; j++) {
    17         if (names[j]==null) {    //等于空就是没有数据
    18             if (sums[j]==null || sums.length<id) {    //数组为空      选择和下标    对比   
    19                 System.out.println("没有该菜品编号,请重新选择");
    20                 Exit();
    21                 break;
    22             }else {
    23                  System.out.println("请选择你需要的份数");
    24                   int num=input.nextInt();
    25                   
    26                   System.out.println("请输入送餐时间(送餐时间是10点至20点间整点送餐:)");
    27                   int time=input.nextInt();
    28                   
    29                   if (time>=20 || time<=10) {
    30                     System.out.println("时间不合法!!!");
    31                     Dinner();
    32                     return;
    33                 }
    34                   
    35                   System.out.println("请输入送餐地址:");
    36                   String add=input.next();
    37                   
    38                 for (int i = 0; i < sums.length; i++) {
    39                     if (sums[i]!=null) {   
    40                         if (i==id) {
    41                             names[i]=name;
    42                             if (num!=0) {
    43                                 sumPrice[i]=sumPrice[i]*num;
    44                             }
    45                             addres[i]=add;
    46                             System.out.println(sums[i]+num+"份"+"???"+names[i]);
    47                             System.out.println(time+"点"+sumPrice[i]*num+"送餐费0.0元"+sumPrice[i]*num++);
    48                            break;
    49                         }
    50                     }    
    51                 }
    52                      Exit();    
    53             }
    54         }
    55     }
    56      
    57      
    58     }
    订餐Dinner()

    4.查看

     1 //查看
     2     public static void Show() {
     3       System.out.println("*****查看餐袋*****");    
     4         System.out.println("序号"+"			"+"订餐人"+"			"+"菜品信息"+"				"+"送餐日期"+"			"+"地址"+"			"+"价钱"+"			"+"状态"+"			"+"赞总计");
     5      String temp= null;//ShowUtil();                 //辅助方法
     6       for (int i = 0; i <names.length ; i++) {
     7            if (names[i]==null) {
     8             continue;
     9         }else {
    10             if (states[i]==0) {
    11                 temp="已预订";
    12             }else {
    13                 temp="已完成";
    14             }
    15             System.out.println(i+1+"			"+names[i]+"				"+sums[i]+"			"+times[i]+"日"+"				"+addres[i]+"				"+sumPrice[i]+"				"+temp+"				"+upvote[i]);
    16         }
    17     }
    18       Exit();
    19     }
    查看Show()

    5.签收(签收挺恶心的,因为需要比较输入的和状态并且不为空的条件下)

     1 //签到
     2     public static void Sign() {
     3         System.out.println("******签到******");
     4         System.out.println("请选择签到序号");
     5         int num=input.nextInt();
     6         num-=1;
     7      for (int i = 0; i < names.length; i++) {
     8         if (names[i]!=null) {
     9             if (states[i]!=0) {    //说明签到了
    10                 System.out.println("已经签到过!!!");
    11                 break;
    12             }else {
    13                 if (num==i && states[i]==0 &&names[i]!=null) {   //num和i对比   状态与0对比    并且不等于空
    14                     states[num]=1;
    15                     System.out.println("签到成功!!!!");
    16                     break;
    17                 }else {
    18                     System.out.println("已经签到了");
    19                     break;
    20                 }
    21             }
    22         }
    23     }
    24      Exit();
    25     }
    签到Sign()

    6.删除(其实就是让数组初始化)

     1 //删除
     2     public static void delete() {
     3         System.out.println("*****删除订单****");
     4        System.out.println("请输入要删除的订单序号:");
     5         int oper= input.nextInt();
     6         oper-=1;
     7        for (int i = 0; i < names.length; i++) {
     8         if (names[i]!=null) {  
     9             if (oper==i) {   //找到了   置空
    10                 names[i]=null;
    11                 states[i]=0;
    12                 sumPrice[i]=0;
    13                 addres[i]=null;
    14                 times[i]=0;
    15                 System.out.println("删除成功!!!");
    16                 break;
    17             }else {
    18                 System.out.println("删除失败!!!");
    19                 break;
    20             }
    21         }
    22        }
    23        Exit();
    24     }
    删除delete()

    7.点赞

     1 //点赞
     2     public static void Upvote() {
     3         System.out.println("*****点赞****");
     4         System.out.println("请输入序号");
     5         int num=input.nextInt();
     6         num-=num;
     7         for (int i = 0; i < names.length; i++) {
     8             if (names[i]!=null) {
     9                 upvote[i]+=1;
    10                 System.out.println("点赞成功!");
    11                 break;
    12             }
    13         }
    14         Exit();
    15     }
    点赞Upvote()

    8.退出

     1 //退出
     2     public static void  Exit() {
     3         System.out.println("按0返回主菜单");
     4         int operString=input.nextInt();
     5         if (operString==0) {
     6             Menu();
     7         }else {
     8             System.out.println("程序退出!");
     9         }
    10     }
    退出Exit()

    还是需要基础的!!!!!!!!

  • 相关阅读:
    线程、同步
    异常、线程
    Map
    List、Set
    Collection、泛型
    Object类、常用API
    h5-上传图片预览
    js 获取get参数
    《转》完美解决微信video视频隐藏控件和内联播放问题
    写入文件(覆盖文件的内容)
  • 原文地址:https://www.cnblogs.com/quliang/p/6834681.html
Copyright © 2011-2022 走看看