I am working on an assignment where I have to write a program to encrypt and decrypt Caeser ciphers. The part I am having trouble with though is not encrypting or decrypting, but another one of the requirements, which was that I have to provide a menu so that the user can choose to encrypt, decrypt, or quit. Furthermore, the program should keep prompting the use until the use selects quit. My code so far is:
import java.util.*;
public class CaeserShiftTester
{
public static void main (String[] args)
{
Scanner in = new Scanner(System.in);
String choice = "";
while (!choice.equalsIgnoreCase("C"))
{
System.out.println("\nPlease select an option");
System.out.println("[A] Encrypt Code");
System.out.println("[B] Decrypt Code");
System.out.println("[C] Quit");
choice = in.next();
if(choice.equalsIgnoreCase("A"))
{
System.out.println("Please enter your key:");
final int KEY = in.nextInt();
System.out.println(CaeserShiftEncryption.shiftAlphabet(KEY));
System.out.println("\nPlease enter your message:");
String message = in.nextLine();
System.out.println(CaeserShiftEncryption.encryptCode(message,KEY));
}
if(choice.equalsIgnoreCase("C"))
{
System.out.println();
}
}
}
}
My problem is, after the "New Alphabet" is printed out to the screen, the program loops back to the very beginning, asking the user to choose a, b, or c. The use never gets a chance to enter a message to be encrypted. Unfortunately, I am required to print out the New Alphabet that is generated, and I can't think of what might be wrong here. I hope you guys can help me out.
Also, the shiftAlphabet and encryptCode methods are both fully functional.