if (eventName.equals("login")) {
print("欢迎使用饮料售货机系统!请输入对应数字进行操作:\n[1] 用户登陆\n[2] 管理员登陆\n[3] 退出");
try {
switch (service.Present.scanInt()) {
case 1:
event("userCheck");
break;
case 2:
print("请输入管理员账号");
Scanner reader=new Scanner(System.in);
String x=reader.nextLine();
if(x.equals("admin")) {
event("adminMain");
}
else {
print("用户名不正确,系统自动退出");
event("exit");
break;
}
case 3:
event("exit");
break;
default:
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("login");
break;
}
} catch (Exception e) {
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("login");
}
} else if (eventName.equals("userCheck")) {
print("提示:如不存在该用户名则自动建立账号,输入\"返回\"或\"return\"返回登陆界面,用户名不能存在特殊字符和空格。\n请输入用户名:");
String name = service.Present.scanString();
if (name.equals("返回") || name.equals("return")) {
event("login");
} else if (!User.matchRule(name)) {
print("用户名不符合规范,请重新输入");
Present.threadSleep(1000);
event("userCheck");
} else if (User.existName(name) == true) {
User.userName = name;
User.userNo = User.getNo(name);
event("userMain");
} else {
print("正在为您注册新用户。");
Present.threadSleep(100);
User.userName = name;
User.userNo = User.getNo(name);
User.addUser(name);
event("userMain");
}
} else if (eventName.equals("adminMain")) {
print("欢迎您,管理员!请输入对应数字进行操作:\n[1] 补全货物\n[2] 查看所有用户详细信息\n[3] 查看购买历史记录\n[4] 返回登陆界面\n[5] 退出");
try {
switch (service.Present.scanInt()) {
case 1:
event("fillGoods");
break;
case 2:
event("getUser");
break;
case 3:
event("getHistory");
break;
case 4:
event("login");
break;
case 5:
event("exit");
break;
default:
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("adminMain");
break;
}
} catch (Exception e) {
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("adminMain");
}
} else if (eventName.equals("userMain")) {
print("欢迎您," + Storge.vip[User.userNo] + "用户" + User.userName
+ "!请输入对应数字进行操作:\n[1] 余额查询 \n[2] 账户充值\n[3] 购买\n[4] 会员中心\n[5] 切换用户\n[6] 退出");
try {
switch (service.Present.scanInt()) {
case 1:
event("balance");
break;
case 2:
event("charge");
break;
case 3:
event("buy");
break;
case 4:
event("vip");
break;
case 5:
event("login");
break;
case 6:
event("exit");
break;
default:
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("userMain");
break;
}
} catch (Exception e) {
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("userMain");
}
} else if (eventName.equals("fillGoods")) {
print("货架已经填充。");
Storge.writeDefaultBeverage();
Storge.in_Server();
event("adminMain");
} else if (eventName.equals("getUser")) {
String text = "";
String[][] list = IO.deleteArrayNull(Storge.user);
for (int i = 0; i < list.length; i++) {
if (list[i] == null || list[i].length == 0) {
break;
}
for (int j = 0; j < list[i].length; j++) {
text = text + list[i][j] + " ";
}
text = text + "\n";
}
text = text + "\n输入任意内容以返回管理员菜单。";
print(text);
service.Present.scanString();
event("adminMain");
} else if (eventName.equals("getHistory")) {
Storge.in_History();
String text = "";
String[][] list = IO.deleteArrayNull(Storge.history);
for (int i = 0; i < list.length; i++) {
if (list[i] == null || list[i].length == 0) {
break;
}
for (int j = 0; j < list[i].length; j++) {
text = text + list[i][j] + " ";
}
text = text + "\n";
}
text = text + "\n输入任意内容以返回管理员菜单。";
print(text);
service.Present.scanString();
event("adminMain");
} else if (eventName.equals("balance")) {
print("用户" + User.userName + "的余额为: " + Storge.balance[User.userNo] + " 元。\n输入任意内容以返回用户菜单。");
service.Present.scanString();
event("userMain");
} else if (eventName.equals("charge")) {
print("请输入1~1000以内的数字进行充值(单位:元):");
try {
double amount = service.Present.scanDouble();
if (amount >= 1 && amount <= 1000) {
User.charge(amount);
print("充值成功!现在您的余额为: " + Storge.balance[User.userNo] + " 元。");
Present.threadSleep(1000);
event("userMain");
} else {
print("充值金额超过限定额度,请重新充值。");
Present.threadSleep(1000);
event("userMain");
}
} catch (Exception e) {
print("输入格式错误,请重新输入!");
Present.threadSleep(1000);
event("userMain");
}
} else if (eventName.equals("buy")) {
String str = User.createGoodsTable() + "输入对应编号购买,输入其他任意内容返回用户菜单:";
show(str);
try {
int number = service.Present.scanInt();
if (number > 0 && number <= 10) {
switch (User.buy(Storge.nameList[number - 1])) {
case -2:
print("当前余额为 " + Storge.balance[User.userNo] + " 元,无法购买该商品!请充值。");
Present.threadSleep(2000);
event("buy");
break;
case -1:
print("购买失败。商品" + Storge.nameList[number - 1] + "已缺货,请提醒管理员补充货物。");
Present.threadSleep(2000);
event("buy");
break;
case 0:
print("没有该商品,请重新购买。");
Present.threadSleep(2000);
event("buy");
break;
case 1:
User.refreshUser();
User.setHistory(Storge.nameList[number - 1]);
Storge.out_All();
print("购买成功!\n“嗝” 你把它喝完了,你觉得充满了决心。当前余额为 " + Storge.balance[User.userNo] + " 元。");
Present.threadSleep(2000);
event("buy");
break;
}
} else {
event("userMain");
}
} catch (Exception e) {
event("userMain");
}
} else if (eventName.equals("vip")) {
if (Storge.vip[User.userNo].equals("会员")) {
print("您目前已经是会员,享有" + Storge.discount4Vip + "倍原价的购买优惠!");
Present.threadSleep(2000);
event("userMain");
} else {
print("您目前是非会员,可以花费60元成为本月会员,享受" + Storge.discount4Vip + "倍原价的购买优惠!\n输入对应数字进行操作:\n[1] 成为会员 \n[2] 返回菜单");
try {
switch (service.Present.scanInt()) {
case 1:
if (User.joinVip()) {
print("办理成功!您已经成为本月会员!现在您的余额为 " + Storge.balance[User.userNo] + " 元。");
Present.threadSleep(2000);
event("userMain");
} else {
print("办理失败!您的余额不足60元,请重新办理!");
Present.threadSleep(2000);
event("userMain");
}
break;
case 2:
event("userMain");
break;
default:
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("userMain");
break;
}
} catch (Exception e) {
print("输入错误,请重新输入!");
Present.threadSleep(1000);
event("UserMain");
}
}
} else if (eventName.equals("exit")) {
print("欢迎再次使用!");
Present.threadSleep(750);
System.exit(-1);
}