@@ -69,12 +69,12 @@ public static String decode(String encryptedMessage, int shift) {
69
69
final int length = encryptedMessage .length ();
70
70
for (int i = 0 ; i < length ; i ++) {
71
71
char current = encryptedMessage .charAt (i );
72
- if (current >= 'A' && current <= 'Z' ) {
72
+ if (IsCapitalLatinLetter ( current ) ) {
73
73
74
74
current -= shift ;
75
75
decoded += (char ) (current < 'A' ? current + 26 : current );// 26 = number of latin letters
76
76
77
- } else if (current >= 'a' && current <= 'z' ) {
77
+ } else if (IsSmallLatinLetter ( current ) ) {
78
78
79
79
current -= shift ;
80
80
decoded += (char ) (current < 'a' ? current + 26 : current );// 26 = number of latin letters
@@ -86,6 +86,24 @@ public static String decode(String encryptedMessage, int shift) {
86
86
return decoded ;
87
87
}
88
88
89
+ /**
90
+ *
91
+ * @param c
92
+ * @return true if character is capital Latin letter or false for others
93
+ */
94
+ private static boolean IsCapitalLatinLetter (char c ) {
95
+ return c >= 'A' && c <= 'Z' ;
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @param c
101
+ * @return true if character is small Latin letter or false for others
102
+ */
103
+ private static boolean IsSmallLatinLetter (char c ) {
104
+ return c >= 'a' && c <= 'z' ;
105
+ }
106
+
89
107
/**
90
108
*
91
109
* @deprecated TODO remove main and make JUnit Testing
@@ -99,11 +117,14 @@ public static void main(String[] args) {
99
117
int shift = input .nextInt () % 26 ;
100
118
System .out .println ("(E)ncode or (D)ecode ?" );
101
119
char choice = input .next ().charAt (0 );
102
- if (choice == 'E' || choice == 'e' ) {
103
- System .out .println ("ENCODED MESSAGE IS \n " + encode (message , shift )); //send our function to handle
104
- }
105
- if (choice == 'D' || choice == 'd' ) {
106
- System .out .println ("DECODED MESSAGE IS \n " + decode (message , shift ));
120
+ switch (choice ) {
121
+ case 'E' :
122
+ case 'e' :
123
+ System .out .println ("ENCODED MESSAGE IS \n " + encode (message , shift )); //send our function to handle
124
+ break ;
125
+ case 'D' :
126
+ case 'd' :
127
+ System .out .println ("DECODED MESSAGE IS \n " + decode (message , shift ));
107
128
}
108
129
}
109
130
0 commit comments