1 import java.util.Scanner; 2 public class Shao { 3 private static final int[] dishNames = null; 4 private static final Object[] dishMegs = null; 5 private static int time; 6 private static int signOrderId; 7 private static int[] tates; 8 private static int delId; 9 private static int endIndex; 10 private static int deiId; 11 public static void main(String[] args, Scanner input) { 12 // TODO Auto-generated method stub 13 String[]names=new String[4];//保存订单人名字 14 String[] dishMegs=new String[4];//保存全部信息 15 int []times=new int[4];//保存送餐时间 16 String[]addresses=new String[4];//保存送货地址 17 int []states=new int[4];//保存订单状态 18 double []sumPrices=new double[4];//保存订单金额 19 for (int j = j-1; j < names.length-1; j++) { 20 names[j]=names[j+1]; 21 dishMegs[j]=dishMegs[j+1]; 22 times[j]=times[j+1]; 23 addresses[j]=addresses[j+1]; 24 states[j]=states[j+1]; 25 sumPrices[j]=sumPrices[j+1]; 26 //用户点菜 27 System.out.print("请选择你要点的菜品编号:"); 28 int chooseDish=input.nextInt(); 29 System.out.print("请选择需要的分数:"); 30 int number=input.nextInt(); 31 String disshMeg=dishMegs[chooseDish-1]+" "+number+"份"; 32 double sumPrice=sumPrices[chooseDish-1]*number; 33 //计算送餐额度 34 double deliCharga=(sumPrice>=50)?0:5; 35 //选择的菜品信息 36 String []dishNums={"红烧带鱼","鱼香肉丝","时令鲜疏"};//菜名字 37 double[]prices=new double[]{38.0,20.0,10.0};//菜品单价 38 int []praiseNums=new int[3]; 39 //开始订单信息 40 names[0]="少华"; 41 dishMegs[0]="红烧带鱼2份:"; 42 times[0]=12; 43 addresses[0]="五道口暂安处北大青鸟2楼:"; 44 sumPrices[0]=1; 45 states[1]=0; 46 //第二个订单 47 names[1]="小雪"; 48 dishMegs[1]="鱼香肉丝1份"; 49 times[1]=14; 50 addresses[1]="五道口展春路华泰公寓202号"; 51 sumPrices[1]=45.0; 52 states[1]=0; 53 //使用do-whil结果实现主菜单操作 54 Scanner input1=new Scanner(System.in); 55 int num=-1;//用户输入0返回主菜单,否则退出系统 56 Object Exit=false;//标志用户是否退出 57 System.out.println("\n欢迎使用吃“货联盟系统:”");//根据用户选择菜单功能 58 do{ 59 //菜单显示 60 System.out.println("*******************************"); 61 System.out.println("1.我要订餐"); 62 System.out.println("2.查看餐袋"); 63 System.out.println("3.签收订餐"); 64 System.out.println("4.删除订餐"); 65 System.out.println("5.我要点赞"); 66 System.out.println("6.退出系统"); 67 System.out.println("1.我要订餐"); 68 System.out.println("************************************"); 69 System.out.println("请选择:"); 70 int choose=input.nextInt();//记录用户选择的功能编号 71 //根据用户输入的功能编号执行相应功能 72 //1 73 if(!Exit) { 74 System.out.print("输入0返回:"); 75 num=input.nextInt(); 76 }else{ 77 break; 78 } 79 } while(num==0); 80 //根据用户输入的功能执行相应功能 81 switch (chooseDish){ 82 case 1: 83 //我要订餐 84 System.out.println("****我要订餐****"); 85 break; 86 case 2: 87 //查看餐袋 88 System.out.println("****查看餐袋****"); 89 break; 90 case 3: 91 //签收订单 92 System.out.println("****签收订单****"); 93 break; 94 case 4: 95 //删除订单 96 System.out.println("****删除订单****"); 97 break; 98 case 5: 99 //我要点赞 100 System.out.println("****我要点赞****"); 101 break; 102 case 6: 103 Object ture; 104 //退出系统 105 Exit=true; 106 break; 107 default: 108 //退出系统 109 Exit=true; 110 break; 111 } 112 //省率代码。。。。。 113 System.out.println("***查看餐袋***"); 114 System.out.println("序号\t订餐人\t产品信息\t\t送餐日期\t送餐地址\t\t总金额" 115 + "\t订单\t订单状态"); 116 for (int i = 0; i < names.length; i++) { 117 if(names[i]!=null){ 118 String state=(states[i]==0)?"已预订":"已完成"; 119 String date=times[i]+"日"; 120 String sumPrice1=sumPrices[i]+"元"; 121 System.out.println((i+1)+"\t"+names[i]+"\t"+dishMegs 122 [i]+"\t"+date+"\t"+addresses[i]+"\t"+sumPrice+ 123 "\t"+state); 124 } 125 } 126 break; 127 } 128 //我要订餐 129 System.out.println("****我要订餐****"); 130 Boolean isAdd=false;//是否可以订餐 131 for (int j = 0; j <names.length; j++) { 132 133 } 134 int j; 135 if(names[j]==null){//可以添加订单信息 136 isAdd=true;//置标志可以订餐 137 System.out.print("请输入订餐人姓名:"); 138 String name=input.next(); 139 //显示选择菜品信息 140 System.out.println("序号"+"\t"+"菜品"+"\t"+"单价"+"\t"+"点赞数"); 141 for (int i = 0; i < name.length(); i++) { 142 String price=sumPrices[i]+"元"; 143 String priaiseNum=(states[i])>0?states[i]+"赞":"0"; 144 System.out.println((i+1)+"\t"+names[i]+"\t"+price 145 +"\t"+priaiseNum); 146 } 147 //用户点菜 148 System.out.print("请选择要点的菜品编号:"); 149 int chooseDish=input.nextInt(); 150 System.out.println("请选择您需要的份数"); 151 int number=input.nextInt(); 152 Comparable<String> dishNMeg=dishNames[chooseDish-1]*number+" "+number+"份"; 153 double sumPrice=sumPrices[chooseDish-1]*number;//餐费满五十一免费送餐 154 double deliChaeg=(sumPrice>=50)?0:0.5; 155 while(time<10||time>20){ 156 System.out.print("请输入送餐时间(10点之20点左右送到):"); 157 int time=input.nextInt(); 158 } 159 System.out.print("请输入送餐地址:"); 160 String address=input.next(); 161 //无需添加状态 162 System.out.println("订餐成功"); 163 System.out.println("您订的是:"+dishMegs); 164 System.out.println("送餐时间:"+time+"点"); 165 Object 总计; 166 System.out.printf("餐费:"+sumPrice+"元","送餐费"+deliChaeg 167 +"元"总计,": "+(sumPrice"+ deliChaeg)+"元";" 168 //添加数据 169 names[j]=name; 170 dishMegs[j]=dishMegs; 171 times[j]=time; 172 addresses[j]=address; 173 sumPrices[j]=sumPrice+deliChaeg; 174 break; 175 } 176 if(!isAdd){ 177 System.out.println("对不起,你的餐袋已满"); 178 } 179 break; 180 //签收订单 181 System.out.println("***签收订单***"); 182 boolean inSignFind=false;//找到要签收的单子 183 System.out.println("请选择要签收的订单序列号:"); 184 int ingnOrderId=input.nextInt(); 185 for (int i = 0; i < names.length; i++) { 186 // 187 // 188 if(names[i]!=null&&states[i]==0&&signOrderId==i+1){ 189 states[i]=i; 190 System.out.println("订单签收成功!"); 191 inSignFind=true; 192 }else if(names[i]!=null&&tates[i]==1&&signOrderId==i+1){ 193 System.out.println("您选择的订单已签收完成,不能再次签收!"); 194 inSignFind=true; 195 } 196 } 197 if(!inSignFind){ 198 System.out.println("您选择的订单不存在!"); 199 } 200 break; 201 //删除订单 202 System.out.println("***删除订单***"); 203 boolean isDelFind=false; 204 System.out.println("请输入删除订单序列号:"); 205 int intdelId=input.nextInt(); 206 for (int i = 0; i < names.length; i++) { 207 if(names[i]!=null&&states[i]==1&&delId==i+1){ 208 isDelFind=true; 209 for (int j1 = delId-1; j1 < names.length; j1++) { 210 names[j]=names[j+1]; 211 dishMegs[endIndex]=null; 212 addresses[j]=addresses[j+1]; 213 states[j]=states[j+1]; 214 sumPrices[j]=sumPrices[j+1]; 215 times[j]=times[j+1]; 216 } 217 //最后一位清空 218 int endIndex =names.length-1; 219 names[endIndex]=null; 220 dishMegs[endIndex]=null; 221 times[endIndex]=0; 222 addresses[endIndex]=null; 223 states[endIndex]=0; 224 sumPrices[endIndex]=0; 225 System.out.println("删除订单成功!"); 226 break; 227 }else if(names[i]!=null&&states[i]==0&&deiId==i+1){ 228 System.out.println("请选择的订单未签收,不能删除:"); 229 isDdlFind=true; 230 break; 231 } 232 } 233 if(!isDdlFind){ 234 System.out.println("你要删除的订单不存在!:"); 235 } 236 break; 237 System.out.println("***我要点赞***"); 238 //显示菜品信息 239 System.out.println("序号"+"\t"+"菜品"+"\t"+"单价"); 240 for (int k = 0; k < dishNames.length; k++) { 241 String price=prices[k]+"元"; 242 String priaiseNum=(priaiseNum[k])>0?priaiseNum[k]+"赞":""; 243 System.out.println((k+1)+"\t"+dishNames[i]+"\t"+price+"\t"+priaiseNum); 244 } 245 System.out.print("请选择您要点赞的菜品序号:"); 246 int priaiseNum=input.nextInt(); 247 praiseNuns[priaiseNum-1]++;//参数家+1 248 System.out.println("点赞成功!"); 249 break; 250 } 251 252 }
简单的Java小程序