Explorar el Código

all methods written and all tests pass

Margaret Pierse hace 6 años
padre
commit
e0ef8c41aa
Se han modificado 1 ficheros con 7 adiciones y 2 borrados
  1. 7
    2
      LoopFun.java

+ 7
- 2
LoopFun.java Ver fichero

@@ -32,7 +32,6 @@ public class LoopFun
32 32
               result = result + phrase.substring(firstSpaceIndex+1, firstSpaceIndex+2);
33 33
               phrase = phrase.substring(0,firstSpaceIndex) + phrase.substring(firstSpaceIndex+1);
34 34
               firstSpaceIndex = phrase.indexOf(" ");
35
-              System.out.print(result);
36 35
             }
37 36
           return result;
38 37
       }
@@ -50,6 +49,12 @@ public class LoopFun
50 49
        * @return the encrypted string by shifting each character by three character
51 50
        */
52 51
       public String encrypt(String word) {
53
-          return null;
52
+          String alphabet = "abcdefghijklmnopqrstuvwxyzabcde";
53
+          String codedWord = "";
54
+          for (int i=0; i<word.length(); i++) {
55
+            int alphaIndex = alphabet.indexOf(word.charAt(i));
56
+              codedWord += String.valueOf(alphabet.charAt(alphaIndex+3));
57
+            }
58
+          return codedWord;
54 59
       }
55 60
 }