Browse Source

finished quiz

Christian Sheridan 6 years ago
parent
commit
3536f65572
1 changed files with 21 additions and 11 deletions
  1. 21
    11
      LoopFun.java

+ 21
- 11
LoopFun.java View File

@@ -26,22 +26,23 @@ public class LoopFun
26 26
     public String acronym(String phrase) {
27 27
        
28 28
         String[] parts = phrase.split(" ");
29
-        /* This is what I wanted to do
29
+        //This is what I wanted to do
30 30
         int i;
31 31
         int lengthOfString = parts.length;
32
+        String part1 = "";
32 33
         for (i = 0; i < lengthOfString; i++){
33
-        String part1 = parts[i];
34
-        String part2 = part1.substring(0,1).toUpperCase();
35
-      
36
-    }*/
34
+         part1 += parts[i].substring(0,1).toUpperCase();
35
+        }
36
+        return part1;
37
+    }
37 38
         
38
-        String part1 = parts[0];
39
+        /*String part1 = parts[0];
39 40
         String part2 = parts[1];
40 41
         String part3 = parts[2];
41 42
         
42 43
         String q = part1.substring(0,1).toUpperCase() + part2.substring(0,1).toUpperCase() + part3.substring(0,1).toUpperCase();
43
-        return q;
44
-    }
44
+        return q;*/
45
+    
45 46
 
46 47
     /**
47 48
      * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
@@ -56,6 +57,15 @@ public class LoopFun
56 57
      * @return the encrypted string by shifting each character by three character
57 58
      */
58 59
     public String encrypt(String word) {
59
-        return null;
60
-    }
61
-}
60
+        String word2 = "";
61
+        int i;
62
+        int lengthOfChar = word.length();
63
+        for(i = 0; i <lengthOfChar; i++){
64
+            char c = word.charAt(i);
65
+            if (c > 'w')
66
+            word2+= (char)(word.charAt(i) -23);
67
+            else
68
+            word2+= (char)(word.charAt(i) + 3);} 
69
+            return word2;
70
+            }
71
+        }