Browse Source

all methods written and all tests pass

Margaret Pierse 6 years ago
parent
commit
e0ef8c41aa
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      LoopFun.java

+ 7
- 2
LoopFun.java View File

32
               result = result + phrase.substring(firstSpaceIndex+1, firstSpaceIndex+2);
32
               result = result + phrase.substring(firstSpaceIndex+1, firstSpaceIndex+2);
33
               phrase = phrase.substring(0,firstSpaceIndex) + phrase.substring(firstSpaceIndex+1);
33
               phrase = phrase.substring(0,firstSpaceIndex) + phrase.substring(firstSpaceIndex+1);
34
               firstSpaceIndex = phrase.indexOf(" ");
34
               firstSpaceIndex = phrase.indexOf(" ");
35
-              System.out.print(result);
36
             }
35
             }
37
           return result;
36
           return result;
38
       }
37
       }
50
        * @return the encrypted string by shifting each character by three character
49
        * @return the encrypted string by shifting each character by three character
51
        */
50
        */
52
       public String encrypt(String word) {
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
 }