1. 程式人生 > >作業:吃貨聯盟

作業:吃貨聯盟

package com.bd22;

import java.util.Scanner;

/*
 * 歡迎使用“吃貨聯盟訂餐系統
 * 1.我要訂餐
 * 2.檢視餐袋
 * 3.簽收訂單
 * 4.刪除訂單
 * 5.我要點贊
 * 6.退出系統
 */
public class Work1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num = -1;
        boolean isExit = false;
        String[]names 
= new String[4]; String[]dishMegs = new String[4]; int[]times = new int[4]; String[]addresses = new String[4]; String[]dishNames = {"紅燒帶魚","魚香肉絲","時令鮮蔬"}; double[]prices = new double[] {38.0,20.0,10.0}; int[]praiseNums =new int[3]; int[]states = new
int[4];//儲存訂單狀態:0已經預定;1已經完成 double[]sumPrices = new double[4]; System.out.println("歡迎使用“吃貨聯盟訂餐系統”"); do { System.out.println("1.我要訂餐"); System.out.println("2.檢視餐袋"); System.out.println("3.簽收訂單"); System.out.println("4.刪除訂單"); System.
out.println("5.我要點贊"); System.out.println("6.退出系統"); System.out.println("請選擇:"); int choose = input.nextInt(); switch(choose){ case 1: System.out.println("我要訂餐"); Boolean isAdd = false; for(int j = 0;j<names.length;j++) { if(names[j]==null) { isAdd = true; System.out.println("請輸入訂餐人姓名:"); String name = input.next(); System.out.println("序號"+"\t"+"菜名"+"\t"+"單價"+"\t"+"點贊數"); for(int i= 0;i<dishNames.length;i++) { String price =prices[i]+""; String priaiseNum =(praiseNums[i])>0?praiseNums[i]+"":"0"; System.out.println((i+1)+"\t"+dishNames[i]+"\t"+price+"\t"+priaiseNum); } System.out.println("請選擇您要點的菜品編號:"); int chooseDish = input.nextInt(); System.out.println("請選擇您需要的份數:"); int number = input.nextInt(); String dishMeg = dishNames[chooseDish-1]+""+number+""; double sumPrice = prices[chooseDish-1]*number; double deliCharge = 5; System.out.println("請輸入送餐時間(送餐時間是10點至20點整點送餐):"); int time = input.nextInt(); while(time<10||time>20) { System.out.println("您的輸入有誤,請輸入10~20間的整數!"); time = input.nextInt(); } System.out.println("請輸入送餐地址:"); String address = input.next(); System.out.println("訂餐成功!"); System.out.println("您訂的是:"+dishMeg); System.out.println("送餐時間為"+time+""); System.out.println("餐費為:"+sumPrice+"元,送餐費"+deliCharge+"元,總價:"+(sumPrice+deliCharge)+"元。"); names[j]=name; dishMegs[j]=dishMeg; times[j]=time; addresses[j]=address; sumPrices[j]=sumPrice+deliCharge; break; } if(!isAdd) { System.out.println("對不起,您的餐袋已滿!"); } break; } break; case 2: System.out.println("檢視餐袋"); System.out.println("序號\t訂餐人\t餐品資訊\t\t送餐時間\t送餐地址\t\t總金額\t訂單狀態"); for(int i = 0;i<names.length;i++) { if(names[i]!=null) { String state = (states[i]==0)?"已經預定":"已經完成"; String date = times[i]+""; String sumPrice = sumPrices[i]+""; System.out.println((i+1)+"\t"+names[i]+"\t"+dishMegs[i]+"\t\t"+date+"\t"+addresses[i]+"\t\t"+sumPrice+"\t"+state); } } break; case 3: System.out.println("簽收訂單"); boolean isSignFind = false; System.out.println("請選擇要簽收的訂單序號:"); int signOrderld = input.nextInt(); for(int i =0;i<names.length;i++) { if(names[i]!=null&&states[i]==0&&signOrderld==i+1) { states[i]=1; System.out.println("訂單簽收成功!"); isSignFind = true; }else if(names[i]!=null&&states[i]==1&&signOrderld==i+1) { System.out.println("您選擇的訂單已簽收,不能再次簽收!"); isSignFind = true; } } if(!isSignFind) { System.out.println("您選擇的訂單不存在!"); } break; case 4: System.out.println("刪除訂單"); boolean isDelFind = false; System.out.println("請輸入要刪除的訂單序號:"); int delId = input.nextInt(); for(int i = 0;i<names.length;i++) { if(names[i]!=null&&states[i]==1&&delId==i+1) { isDelFind = true; for(int j =delId-1;j<names.length-1;j++) { names[j] =names[j+1]; dishMegs[j]=dishMegs[j+1]; times[j]=times[j+1]; addresses[j]=addresses[j+1]; states[j]=states[j+1]; sumPrices[j]=sumPrices[j+1]; } int endIndex = names.length-1; names[endIndex]=null; dishMegs[endIndex]=null; times[endIndex]=0; addresses[endIndex]=null; states[endIndex]=0; sumPrices[endIndex]=0; System.out.println("刪除訂單成功!"); break; }else if(names[i]!=null&&states[i]==0&&delId==i+1) { System.out.println("您選擇的訂單未簽收,不能刪除!"); isDelFind = true; break; } } if(!isDelFind) { System.out.println("您要刪除的訂單不存在!"); } break; case 5: System.out.println("我要點贊"); System.out.println("序號"+"\t"+"菜名"+"\t"+"單價"); for(int i = 0;i<dishNames.length;i++) { String price = prices[i]+""; String priaiseNum =(praiseNums[i])>0?praiseNums[i]+"":""; System.out.println("(i+1)+"+"\t"+dishNames[i]+"\t"+price+"\t"+priaiseNum); } System.out.println("請選擇您要點讚的菜品序號:"); int priaiseNum = input.nextInt(); praiseNums[priaiseNum-1]++; System.out.println("點贊成功!"); break; case 6: isExit = true; break; default: isExit = true; System.out.println("您的輸入有誤系統已崩潰,如需使用請重啟系統"); break; } if(!isExit) { System.out.println("輸入0返回:"); num = input.nextInt(); }else { break; } }while(num==0); } }