我在大学里有一个项目来创建一个登录菜单类型的应用程序。
我非常喜欢初学者,请耐心等待。 我是否可以要求有人指出我正确的方向,因为我在这个方面有点空白。
应用程序还没有完成,所以我知道会有更多需要添加它,只知道它只是一个非常准备建立的准系统应用程序。
选择选项1后,应用会告诉用户首先更改密码和尝试。更改密码和尝试后(我在测试时将其更改为5)并重新选择选项1,出现此错误 -
# other imports
import time
# other code
numberOfRetries = 0
while (FoundItem == "Nope"):
# other code
if InStockCheck == "InStock.":
print("Found")
break
elif numberOfTries > 4:
print("Not found after waiting for 5 seconds")
break
else:
print("Yellow")
numberOfRetries = numberOfRetries + 1
time.sleep(1)
print("Pink")
这是代码 -
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - not a statement
at loginmenu.LoginMenu.loginAttempt(LoginMenu.java:74)
at loginmenu.LoginMenu.showMenu(LoginMenu.java:34)
at loginmenu.LoginMenu.loginAttempt(LoginMenu.java:77)
at loginmenu.LoginMenu.showMenu(LoginMenu.java:34)
at loginmenu.LoginMenu.main(LoginMenu.java:12)
答案 0 :(得分:1)
修复括号并抛弃分号,不要使用==
/ !=
作为字符串。
while (correctPassword != userPassword) && (attemptsCounter>=5);
应该是
while (!correctPassword.equals(userPassword) && (attemptsCounter>=5))
括号中的同一问题:
if (userPassword == correctPassword) && (attemptsCounter<=5)
答案 1 :(得分:0)
这是我对你提问的方法。
首先,我将密码设置在第一位。
VARLENA
而且,我只能在这种情况下调用showMenu方法。
VARCHAR
您不必在loginAttempt中调用showMenu方法,并且还会删除while语句。
private static String correctPassword = "tommybee";
在showMenu方法中,我只使用一个具有系统输入流的扫描仪类。 检查the scanner class。
声明一个Scanner类并将userChoice变量初始化为4。
public static void main(String[] args) {
showMenu();
}
这是showMenu方法。
public static void loginAttempt() {
if (!(userPassword.toLowerCase().equals(correctPassword)) && (attemptsCounter >= 5)) {
System.out.println("Please change password and attempts first.");
}
if ((correctPassword.toLowerCase().equals(userPassword)) && (attemptsCounter <= 5)) {
System.out.println("You entered the correct password in " + attemptsCounter + " attempts");
}
if (attemptsCounter >= 6) {
System.out.println("You have been locked out.");
}
}
我使用next方法而不是nextInt方法。 请参阅api文档的next method。
此方法可能在等待输入扫描时阻塞,
这就是我所做的。
Scanner myScan = new Scanner(System.in);
int userChoice = 4;