Assignment 2
Assignment 2
import java.util.Scanner;
Assignment 2 1
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice;
do {
displayMenu();
choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1: // Encode a message
System.out.print("Enter the message to encod
String messageToEncode = scanner.nextLine();
System.out.print("Enter the shift value: ");
int encodeShift = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.println("Encoded Message: " + enc
break;
case 2: // Decode a message
System.out.print("Enter the message to decod
String messageToDecode = scanner.nextLine();
System.out.print("Enter the shift value: ");
int decodeShift = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.println("Decoded Message: " + dec
break;
case 3: // Exit
System.out.println("Exiting the program. Goo
break;
default:
System.out.println("Invalid choice. Please t
}
} while (choice != 3);
scanner.close();
Assignment 2 2
}
}
Assignment 2 3