プログラムは、main で while ループ メニューを使用して、ユーザー コマンドを要求します。
public static void main(String[] args)throws Exception
{
Boolean meow = true;
while(meow)
{
System.out.println("\n 1. Show all records.\n"
+ " 2. Delete the current record.\n"
+ " 3. Change the first name in the current record.\n"
+ " 4. Change the last name in the current record.\n"
+ " 5. Add a new record.\n"
+ " 6. Change the phone number in the current record.\n"
+ " 7. Add a deposit to the current balance in the current record.\n"
+ " 8. Make a withdrawal from the current record if sufficient funds are available.\n"
+ " 9. Select a record from the record list to become the current record.\n"
+ " 10. Quit.\n");
System.out.println("Enter a command from the list above (q to quit): ");
answer = scan.nextLine();
cmd.command(answer);
if(answer.equalsIgnoreCase("10") || answer.equalsIgnoreCase("q"))
{
meow = false;
}
}
}
選択したコマンドが実際にはメニューのコマンドではない場合、次のことが起こります。
else
{
System.out.println("Illegal command");
System.out.println("Enter a command from the list above (q to quit): ");
answer = scan.nextLine();
command(answer);
}
新しい人物を追加したり、値の入力を終了するために Return キーを押す必要のあるコマンドを使用したりするたびに、else ステートメントが表示され、次に通常のコマンド リクエストが表示されます。
したがって、次のようになります。
Enter a command from the list above (q to quit):
Illegal command
Enter a command from the list above (q to quit):
これが起こるとき。
ここに私の完全なコードを投稿するつもりはありません。代わりにそれらのペーストビンを用意してください。
- 私の完全なメイン クラス: http://pastebin.com/rUuKtpXb
- 私の完全ではないメインクラス: http://pastebin.com/UE4H76Cd
なぜこれが起こっているのか知っている人はいますか?