So. I'm doing a tutorial on java and playing with making a D&D character sheet saver. The problem I'm having is not a serious one but after I've commanded it to load, it does the message as expected but then when I input 'new' and hit enter it waits until I hit enter again and then it does my else code instead of my if for "new". I end up having to type it again.
do {
if (command.equalsIgnoreCase("new")) {
System.out.println("Let's create a character!\n");
// ...then a bunch of other code that doesn't matter and then:*
// LOAD CHARACTER
else if (command.equalsIgnoreCase("load")) {
// placeholder for load char.
System.out
.println("This is where we will load a character in the future. For now it is empty, please select new.");
command = text.nextLine();
// EXIT CODE
} else if (command.equalsIgnoreCase("exit")) {
System.exit(0);
// Invalid Response
} else
System.out.println("Invalid response. Please try again. ");
command = text.nextLine();
} while (!command.equalsIgnoreCase("exit"));
and here's how it comes out:
Please say 'New' for a new character or 'Load' to load a previously saved character...
Load
This is where we will load a character in the future. For now it is empty, please select new.
new
Invalid response. Please try again.
new
Let's create a character!
What is this character's name?
Aucun commentaire:
Enregistrer un commentaire