Przeglądaj źródła

rotational-cipher: estimate and tidy

Frida Tveit 9 lat temu
rodzic
commit
7975530e96

+ 7
- 7
config.json Wyświetl plik

@@ -145,6 +145,13 @@
145 145
       ]
146 146
     },
147 147
     {
148
+      "slug": "rotational-cipher",
149
+      "difficulty": 4,
150
+      "topics": [
151
+
152
+      ]
153
+    },
154
+    {
148 155
       "slug": "kindergarten-garden",
149 156
       "difficulty": 4,
150 157
       "topics": [
@@ -539,13 +546,6 @@
539 546
       "topics": [
540 547
 
541 548
       ]
542
-    },
543
-    {
544
-      "slug": "rotational-cipher",
545
-      "difficulty": 1,
546
-      "topics": [
547
-
548
-      ]
549 549
     }
550 550
   ],
551 551
   "deprecated": [

+ 5
- 8
exercises/rotational-cipher/src/example/java/RotationalCipher.java Wyświetl plik

@@ -1,13 +1,12 @@
1
+class RotationalCipher {
1 2
 
2
-public class RotationalCipher {
3
-
4
-    int shiftKey;
3
+    private int shiftKey;
5 4
 
6 5
     RotationalCipher(int shiftKey) {
7 6
         this.shiftKey = shiftKey;
8 7
     }
9 8
 
10
-    public String rotate(String data) {
9
+    String rotate(String data) {
11 10
         StringBuilder dataStringBuilder = new StringBuilder();
12 11
         for (char c : data.toCharArray()) {
13 12
             if (Character.isUpperCase(c)) {
@@ -25,12 +24,10 @@ public class RotationalCipher {
25 24
      * For Uppercase CaseStart = 'A' and CaseEnd = 'Z'
26 25
      * For Lowercase CaseStart = 'a' and CaseEnd = 'z'
27 26
      */
28
-    private char getReplacementCharacter(char characterToReplace,
29
-            char alphabetCaseStart, char alphabetCaseEnd) {
27
+    private char getReplacementCharacter(char characterToReplace, char alphabetCaseStart, char alphabetCaseEnd) {
30 28
         char replacementCharacter = (char) (characterToReplace + shiftKey);
31 29
         if (replacementCharacter > alphabetCaseEnd) {
32
-            replacementCharacter = (char) ((alphabetCaseStart - 1) +
33
-             (replacementCharacter % alphabetCaseEnd));
30
+            replacementCharacter = (char) ((alphabetCaseStart - 1) + (replacementCharacter % alphabetCaseEnd));
34 31
         }
35 32
         return replacementCharacter;
36 33
     }

+ 3
- 6
exercises/rotational-cipher/src/test/java/RotationalCipherTest.java Wyświetl plik

@@ -1,6 +1,4 @@
1
-
2 1
 import org.junit.Assert;
3
-import org.junit.Before;
4 2
 import org.junit.Ignore;
5 3
 import org.junit.Test;
6 4
 
@@ -13,7 +11,7 @@ public class RotationalCipherTest {
13 11
         rotationalCipher = new RotationalCipher(1);
14 12
         Assert.assertEquals("b", rotationalCipher.rotate("a"));
15 13
     }
16
-    
14
+
17 15
     @Ignore("Remove to run test")
18 16
     @Test
19 17
     public void rotateSingleCharacterBy26() {
@@ -75,7 +73,6 @@ public class RotationalCipherTest {
75 73
     public void rotateAllLetters() {
76 74
         rotationalCipher = new RotationalCipher(13);
77 75
         Assert.assertEquals("The quick brown fox jumps over the lazy dog.",
78
-         rotationalCipher.rotate("Gur dhvpx oebja sbk whzcf bire gur ynml qbt."));
79
-    } 
80
-
76
+                rotationalCipher.rotate("Gur dhvpx oebja sbk whzcf bire gur ynml qbt."));
77
+    }
81 78
 }