一个驱动类、输入输出类和 numberValidator 类。用户将使用 j-option 窗格弹出框输入数字 1-8,如果输入的不是 1-8,则应该显示错误消息。如果数字是 1-8,则其余代码(此处未写)应该继续运行。我收到错误,有人看到我错在哪里了吗?
///Driver class (excludes package)////
public class Driver {
public static void main(String[] args) {
InputOutput inputoutput = new InputOutput();
inputoutput.displayMenu();
}
}
///InputOutput class (excludes package and import for JOptionPane)///
public class InputOutput {
public int displayMenu()
{
String stringChoice = JOptionPane.showInputDialog("Restaurant:\n"
+ "1. Pancakes: $10.00\n"
+ "2. Bananas: $1.00\n"
+ "3. Bread: $2.00\n");
if (numberValidator.isNumeric(stringChoice)){
choiceNumber = Integer.parseInt(stringChoice);
}
return choiceNumber;
}
///numberValidator class code (excludes package)///
public class numberValidator {
public boolean isNumeric(String str)
{
boolean valid = true;
String regex = "[1-8/.]*";
valid = str.matches(regex);
return valid;
}
}