Thank you so much for replying, here's the code in hopefully correct format. (+ main method)
import java.util.Scanner;
public class CodeAssignment {
private Scanner input = new Scanner(System.in);
private void newPrintln(String prompt) {
System.out.println(prompt);
}
private void programMenu() {
newPrintln("What would you like to do?"
+ "\n1. register new person. "
+ "\n2. increase age"
+ "\n3. list people"
+ "\n4. remove person"
+ "\n5. exit");
}
public void run() {
initialize();
runCommands();
exitProgram();
}
private void initialize() {
System.out.println("Welcome to the database!");
programMenu();
}
private void runCommands() {
String choice;
do {
System.out.println("> ");
choice = interpretChoice();
excecuteChoice(choice);
} while (choice != "exit" && choice != "5");
}
private String interpretChoice() {
String choice = input.nextLine();
return choice;
}
private void excecuteChoice (String choice) {
switch (choice) {
case "1":
case "register new person":
break;
case "2":
case "increase age":
break;
case "3":
case "list people":
break;
case "4":
case "remove person":
break;
case "5":
case "exit":
break;
default:
newPrintln("Error: no such command."
+ "\nTry again!");
programMenu();
}
}
private void exitProgram() {
newPrintln("Goodbye!");
input.close();
}
public static void main(String[] args) {
CodeAssignment program = new CodeAssignment();
program.run();
}
}
Here are the contents of the command window:
Welcome!
What would you like to do?
1. register new person.
2. increase age
3. list people
4. remove person
5. exit
>
1
>
2
>
3
>
4
>
5
>
exit
>
Even after 5 or "exit" is entered the loop just keeps on going.
(Haven't done methods for the other alternatives yet, which is why everything is blank)
--- Update ---
update, solved it! Thank you for mentioning the string.equals, I'd forgotten about that