-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodeDecodeMain.java
More file actions
56 lines (47 loc) · 2.11 KB
/
EncodeDecodeMain.java
File metadata and controls
56 lines (47 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.io.*;
public class EncodeDecodeMain {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
// System.out.println("Array Size: " + strArr.length);
int choice = -1;
while (true) {
System.out.println("Would you to decode or encode? (Please enter 1 or 2)");
System.out.println("1) Encode");
System.out.println("2) Decode");
System.out.println();
System.out.print("Please enter your choice: ");
String choiceStr = br.readLine();
try {
choice = Integer.valueOf(choiceStr);
if (choice > 2) {
System.err.println("You have entered an incorrect choice. Please try again!");
} else {
break;
}
} catch (NumberFormatException ex) {
System.err.println("You have entered an incorrect choice. Please try again!");
System.out.println();
} catch (Exception ex) {
System.err.println("An unknown error has occured. Please try again!");
System.out.println();
}
}
System.out.println("Your choice is: " + choice);
System.out.print("Please enter the string: ");
String inputStr = br.readLine().toUpperCase();
EncodeDecodeRunner runner = new EncodeDecodeRunner();
if (choice == 2) {
String decodedStr = runner.decode(inputStr, sb);
System.out.println("Your decoded string: " + decodedStr);
} else {
String encodedStr = runner.encode(inputStr, sb);
System.out.println("Your encoded string: " + encodedStr);
}
} catch (Exception ex) {
System.err.println("Error with system. Please restart system.");
}
}
}