我如何验证使用扫描仪生成的otp?假设进行在线预订并生成OTP,并且在验证OTP之后,该项目就被预订了,即使我的NET也有问题,因为最后显示的总数为0。有什么方法可以在执行DEFAULT条件时将代码循环回“选择任何一个”? 代码搞砸了
import java.util.Arrays;
import java.util.Scanner;
import java.util.Random;
public class Restaurant {
static char[] otp(int len) {
String numbers = "0123456789";
Random rand = new Random();
char[] otp = new char[len];
for (int i = 0; i < len; i++) {
otp[i] = numbers.charAt(rand.nextInt(numbers.length()));
}
return otp;
}
public static void main(String[] args) {
int length = 4;
Scanner sc = new Scanner(System.in);
int net, total = 0, item;
//gst = 18 / 100;
String USEROTP;
String Choice;
System.out.println("Welcome to Restaurant");
System.out.println("Todays menu is: ");
System.out.println("1)Dosa\n2)Upma\n3)uttapaa");
System.out.println("Choose any one [1-3]");
item = sc.nextInt();
switch (item) {
case 1:
System.out.println("You Picked up Dosa, which costs Rs: ");
total += 70;
System.out.println(total);
System.out.println("Do you want to confirm ?");
Choice = sc.next();
if (Choice.equals("yes")) {
net = (int) (double) (total + (total + (0.18)));
System.out.println("generating otp");
System.out.println("Your OTP is given below");
System.out.println(otp(length));
//NEED TO VERIFY THE OTP HERE THEN BOOK THE ORDER
System.out.println("BOOKED SUCCESFULLY, your bill is: " + net);
} else {
System.out.println("ok, visit next time");
}
break;
case 2:
net = (int) (double) (total + (total + (0.18)));
System.out.println("You Picked up Upma, which cost Rs:");
total += 50;
System.out.println(total);
System.out.println("Do you want to confirm ?");
Choice = sc.next();
if (Choice.equals("yes")) {
System.out.println("generating otp");
System.out.println("Your OTP is given below");
System.out.println(otp(length));
//NEED TO VERIFY THE OTP HERE THEN BOOK THE ORDER
System.out.println("BOOKED SUCCESFULLY, your bill is: " + net);
} else {
System.out.println("ok, visit next time");
}
break;
case 3:
net = (int) (double) (total + (total + (0.18)));
System.out.println("You Picked up uttapaa, which costs Rs:");
total += 40;
System.out.println(total);
System.out.println("Do you want to confirm ?");
Choice = sc.next();
if (Choice.equals("yes")) {
System.out.println("generating otp");
System.out.println("Your OTP is given below");
System.out.println(otp(length));
//NEED TO VERIFY THE OTP HERE THEN BOOK THE ORDER
System.out.println("BOOKED SUCCESFULLY, your bill is: " + net);
} else {
System.out.println("ok, visit next time");
}
break;
default:
System.out.println("Pick atleast one");
}
}
}