大家好,我正在做作业,我想了解如何正确完成代码中的第三部分 - 3.查看操作历史记录。(用户执行的所有操作的列表,使用数组以格式存储此信息:“[操作索引]。[操作名称] - [用户输入]”。我还有一个问题 - 应用程序应该工作并接受用户输入,直到他想要退出程序。
Scanner in = new Scanner(System.in);
System.out.println("Please select operation");
System.out.println("1.Encode");
System.out.println("2.Decode");
System.out.println("3.View operation history");
System.out.println("4.Exit program");
Integer userInput = Integer.valueOf(in.nextLine());
if (userInput.equals(1)) {
System.out.println("You chosen encoding operation");
System.out.println("Please choose codec name - caesar or morse");
String userInputEncode = in.nextLine().toLowerCase();
if (userInputEncode.equals("caesar")) {
System.out.println("Enter text to encode");
String userInputEncode2 = in.nextLine().toLowerCase();
System.out.println("Encoded text: " + caesarEncoder.encode(userInputEncode2));
} else if (userInputEncode.equals("morse")) {
System.out.println("Enter text to encode");
String userInputEncode3 = in.nextLine().toLowerCase();
System.out.println("Encoded text: " + morseEncoder.encode(userInputEncode3));
} else
System.out.println("You entered wrong codec name, try one more time");
} else if (userInput.equals(2)) {
System.out.println("You chosen decoding operation");
System.out.println("Please choose codec name - caesar or morse");
String userInputDecode = in.nextLine().toLowerCase();
if (userInputDecode.equals("caesar")) {
System.out.println("Enter text to decode");
String userInputDecode2 = in.nextLine().toLowerCase();
System.out.println("Decoded text: " + caesarDecoder.decode(userInputDecode2));
}
千万里不及你
相关分类