I'm trying to work on my homework for class, and I'm using a switch case to make a command line interface, but I'm having a problem with the part I'm using. When I execute the addCard command, it goes through fine, but then afterwards goes to the default section. When I try using any of the other sections, or use it without the try segment, it works and doesn't go to default. Any thoughts on how to repair this? Code below
public static void cmdLine(String Cmd) {
switch(Cmd) {
case "Help":
case "?":
System.out.println("Available Commands:\naddCard = Add a card!\ndeleteCard = Delete a Card!\nfindCard = Locate Card Number by Name!\nCard (Card Number) = Work with your card");
break;
case "addCard" :
System.out.println ("Enter Account Name:");
String cName = scan.nextLine();
try {
System.out.println ("Enter Account Start Balance:");
int cBal = scan.nextInt();
System.out.println ("Enter Account Number:");
int cNum = scan.nextInt();
PPArray.addCard(cName, cBal,cNum);
} catch (InputMismatchException nfe) {
System.out.println("InputMismatchException: Please try again with only the card number. (Ex. 12345");
break;
}
break;
case "deleteCard" :
System.out.println("here we will have a command to remove the card from the array");
break;
case "Card" :
System.out.println("This will lead to a new function to operate with said card");
break;
case "Exit":
case "exit":
case "Quit":
case "quit":
return;
default :
System.out.println("Invalid Command ('?' or 'Help' for commands)");
System.out.println(PPArray.cardArray[1].name);
}
cmdLine(scan.nextLine());
}