Browse Source

more test

Nuridalia.Hernandez 5 years ago
parent
commit
dbceeab67c
1 changed files with 61 additions and 13 deletions
  1. 61
    13
      src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java

+ 61
- 13
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java View File

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3
+import java.util.Arrays;
3 4
 import java.util.HashSet;
4 5
 import java.util.Set;
5 6
 
@@ -19,44 +20,91 @@ public class StringUtils {
19 20
     }
20 21
 
21 22
     public static String capitalizeMiddleCharacter(String str) {
23
+       int positon;
22 24
 
23
-        return null;
25
+       if (str.length() % 2==0){
26
+           positon = str.length()/ 2 -1;
27
+
28
+       }else {
29
+           positon = str.length()/2;
30
+       }
31
+
32
+
33
+
34
+        return str.substring(0,positon) + str.toUpperCase().charAt(positon)+ str.substring(positon,str.length() - 1);
24 35
     }
25 36
 
26 37
     public static String lowerCaseMiddleCharacter(String str) {
27
-        return null;
38
+
39
+        int middle;
40
+
41
+        if (str.length() % 2==0){
42
+            middle = str.length()/ 2 -1;
43
+
44
+
45
+        }else {
46
+            middle = str.length()/2;
47
+        }
48
+return str.substring(0,middle) + str.toLowerCase().charAt(middle)+ str.substring(middle,str.length()-1);
28 49
     }
29 50
 
30 51
     public static Boolean isIsogram(String str) {
31
-        return null;
52
+        str.toLowerCase();
53
+        char arr [] = str.toCharArray();
54
+        Arrays.sort(arr);
55
+
56
+        for (int i = 0; i <arr.length -1 ; i++) {
57
+            if (arr[i] == arr[i+1]) {
58
+
59
+                return true;
60
+
61
+            }
62
+
63
+        }
64
+        return false;
32 65
     }
33 66
 
34 67
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
35
-        String [] arr = str.split("");
68
+        char [] arr = str.toCharArray();
69
+
36 70
         for (int i = 0; i <arr.length-1; i++) {
37
-            for (int j = i+ 1; j <arr.length; j++) {
38
-                if (arr[i] == arr[j]){
39
-                    return true;
40
-                }
71
+             if ( arr[i]== arr[i + 1]){
72
+                 return true;
73
+             }
41 74
 
42 75
             }
43 76
 
44
-        }
45
-
46 77
 
47 78
 
48 79
         return false;
49 80
     }
50 81
 
51 82
     public static String removeConsecutiveDuplicateCharacters(String str) {
83
+        
52 84
 
53 85
 
54 86
 
55
-
56
-        return null;
87
+        return  ;
57 88
     }
58 89
 
59 90
     public static String invertCasing(String str) {
60
-        return null;
91
+        char [] ch = str.toCharArray();
92
+
93
+        for (int i = 0; i <ch.length ; i++) {
94
+
95
+            char c = ch [i];
96
+            if (Character.isUpperCase(c)){
97
+
98
+                ch [i] = Character.toLowerCase(c);
99
+
100
+            } else if (Character.isLowerCase(c)){
101
+
102
+                ch [i]= Character.toUpperCase(c);
103
+
104
+            }
105
+
106
+        }
107
+        return new String(ch);
108
+
61 109
     }
62 110
 }