代碼如下,還沒寫完:
import java.util.Scanner;
import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;
public class Restaurant_system {
public static void main(String[] args) {
/**吃貨聯(lián)盟訂餐系統(tǒng)
*/
/*數(shù)據(jù)存放體系,以及需要用到的功能 */
String[]name = new String[4]; //保存訂餐人姓名
String[]dishMegs = new String[4];//保存所選信息,包括菜品名以及份數(shù)
int[]times = new int[4];//保存送餐時間
String[]addresses = new String[4];//保存送餐地址
int[]states = new int[4];//保存訂單狀態(tài):0表示已經(jīng)預(yù)定,1表示已經(jīng)完成
double[]sumPrices1 = new double[4];//保存訂單菜品金額
final double SEND_PRICES = 5.;
double[]sumPrices = new double[4];//保存訂單的總金額
Scanner input = new Scanner(System.in);
int choose;
//程序初始化,打印菜單體系
System.out.println("歡迎使用“吃貨聯(lián)盟訂餐系統(tǒng)”");
System.out.println("********************************************");
System.out.println("1、我要訂餐");
System.out.println("2、查看餐袋");
System.out.println("3、簽收訂單");
System.out.println("4、刪除訂單");
System.out.println("5、我要點贊");
System.out.println("6、退出系統(tǒng)");
System.out.println("********************************************");
System.out.print("\n請選擇:");
choose = input.nextInt(); //輸入菜單選項
switch (choose) {
case 1:
System.out.println("***我要訂餐***");
//先檢查一下餐袋時候已經(jīng)滿了,如果已經(jīng)滿了,則無法點餐
int check = 0;//檢查
int check_ok = 0;//檢查到餐袋內(nèi)訂單的數(shù)量
for(;check < name.length;check++){//循環(huán)檢查餐袋,看看有沒有訂單
if (name[check] !=null){//如果不是空
check_ok += 1;//訂單數(shù)量加1
}else{//如果檢查到訂單數(shù)量為空,則進入點餐
break;
}
}
if (check_ok == 4) {//餐袋數(shù)量已滿,終止點單
System.out.println("餐袋已滿,無法點單。");
//返回菜單界面
}else{//餐單數(shù)量未滿,進入點單
System.out.print("請輸入訂餐人姓名:");
name[check] = input.next();//把名字放入姓名數(shù)組
System.out.println("序號\t菜名\t單價\t點贊數(shù)");
System.out.println("1\t紅燒帶魚\t38.0\t0");
System.out.println("2\t魚香肉絲\t20.0\t0");
System.out.println("3\t時令鮮蔬\t10.0\t0");
}
System.out.print("請選擇您要點的菜品編號:");
int number = input.nextInt();
System.out.print("請輸入您需要的份數(shù):");
int copies = input.nextInt();
switch (number) {
case 1:
dishMegs[check] = "紅燒帶魚" +copies + "份";
sumPrices1[check] = 38 * copies;
break;
case 2:
dishMegs[check] = "魚香肉絲" +copies + "份";
sumPrices1[check] = 20 * copies;
break;
case 3:
dishMegs[check] = "時令鮮蔬" +copies + "份";
sumPrices1[check] = 10 * copies;
break;
default:
System.out.println("請輸入1-3的數(shù)字");
break;
}
if (sumPrices1[check] < 50) {
sumPrices[check] = sumPrices1[check] + SEND_PRICES;
}
System.out.println("請輸入送餐時間(送餐時間是10點至20點之間的整點):)");
boolean time_check_ok = true; //設(shè)置一個循環(huán)指令,如果輸入的時間合理,則停止循環(huán),否則就繼續(xù)輸入
do {
int time_check = input.nextInt();
if (time_check <= 20 || time_check>= 10) {
times[check] = time_check;
time_check_ok = false;
}else {
System.out.println("請重新輸入正確的送餐時間:");
}
} while(time_check_ok);
System.out.print("請輸入送餐地址:");
addresses[check] = input.next();
System.out.println("訂餐成功!");
System.out.print("您訂的是:" + dishMegs[check]);
System.out.println("送餐時間:" + times[check]);
System.out.println("餐費:" + sumPrices1 + "元,送餐費:" + SEND_PRICES + ",總計:" + sumPrices + "元。");
System.out.println("輸入0返回:");
//下面還沒寫完,目前測試的時候,上面部分出現(xiàn)問題。
break;
case 2:
System.out.println("餐袋");
break;
case 3:
System.out.println("簽收");
break;
case 4:
System.out.println("刪除");
break;
case 5:
System.out.println("點贊");
break;
case 6:
System.out.println("退出");
break;
default:
System.out.println("請輸入1-6當(dāng)中的數(shù)字");
break;
}
}
執(zhí)行程序:
要求輸入選項,輸入1
然后彈出,要求輸入名字:
輸入一個名字,比如小明
彈出如下錯誤,檢查了一邊代碼,沒發(fā)現(xiàn)什么問題,具體錯在哪兒呢?
控制臺說了在32行代碼報錯, choose = input.nextInt();這行代碼
Scanner里面的報錯代碼,nextInt方法開始
public String next(Pattern pattern) {
ensureOpen();
if (pattern == null)
throw new NullPointerException();
// Did we already find this pattern?
if (hasNextPattern == pattern)
return getCachedResult();
clearCaches();
// Search for the pattern
while (true) {
String token = getCompleteTokenInBuffer(pattern);
if (token != null) {
matchValid = true;
skipped = false;
return token;
}
if (needInput)
readInput();
else
throwFor();//最后在這行代碼拋出異常。
}
}
InputMismatchException異常,如果下一個標(biāo)記與 Integer 正則表達式不匹配,或者超出范圍,會拋出此異常。第一次要輸入的是1-6的整數(shù)。
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團,成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。