Khalil Saboor hace 8 años
padre
commit
1a304c7785
Se han modificado 2 ficheros con 84 adiciones y 7 borrados
  1. 42
    7
      StringArrayUtils.java
  2. 42
    0
      package.bluej

+ 42
- 7
StringArrayUtils.java Ver fichero

9
      * @return first element of specified array
9
      * @return first element of specified array
10
      */ // TODO
10
      */ // TODO
11
     public static String getFirstElement(String[] array) {
11
     public static String getFirstElement(String[] array) {
12
-        return null;
12
+        return array[0];
13
     }
13
     }
14
 
14
 
15
     /**
15
     /**
17
      * @return second element in specified array
17
      * @return second element in specified array
18
      */
18
      */
19
     public static String getSecondElement(String[] array) {
19
     public static String getSecondElement(String[] array) {
20
-        return null;
20
+        return array[1];
21
     }
21
     }
22
 
22
 
23
     /**
23
     /**
25
      * @return last element in specified array
25
      * @return last element in specified array
26
      */ // TODO
26
      */ // TODO
27
     public static String getLastElement(String[] array) {
27
     public static String getLastElement(String[] array) {
28
-        return null;
28
+        //String[] array = {"brown", "fox", "jumps", "over", "the", "lazy", "dog"};
29
+            String word = "";
30
+        for(int i = 0; i < array.length -1; i++){
31
+                
32
+            return word = array[array.length-1];
33
+            
34
+        
35
+    
36
+        }
37
+        return word;
29
     }
38
     }
30
 
39
 
31
     /**
40
     /**
33
      * @return second to last element in specified array
42
      * @return second to last element in specified array
34
      */ // TODO
43
      */ // TODO
35
     public static String getSecondToLastElement(String[] array) {
44
     public static String getSecondToLastElement(String[] array) {
36
-        return null;
45
+          String word = "";
46
+        for(int i = 0; i < array.length -2; i++){
47
+                
48
+            return word = array[array.length-2];
49
+        }
50
+        return word;
37
     }
51
     }
38
 
52
 
39
     /**
53
     /**
42
      * @return true if the array contains the specified `value`
56
      * @return true if the array contains the specified `value`
43
      */ // TODO
57
      */ // TODO
44
     public static boolean contains(String[] array, String value) {
58
     public static boolean contains(String[] array, String value) {
45
-        return false;
59
+        boolean hold = false;
60
+        for(String s:array){
61
+            if(s.equals(value)){
62
+            return hold = true;
63
+            }
64
+        }
65
+        
66
+        return hold;
46
     }
67
     }
47
-
48
     /**
68
     /**
49
      * @param array of String objects
69
      * @param array of String objects
50
      * @return an array with identical contents in reverse order
70
      * @return an array with identical contents in reverse order
51
      */ // TODO
71
      */ // TODO
52
     public static String[] reverse(String[] array) {
72
     public static String[] reverse(String[] array) {
53
-        return null;
73
+        String [] t = new String [array.length]; 
74
+        for(int i = 0 ;i<array.length;i++){
75
+            t[i] = "";
76
+            for(int j = array[i].length()-1; j>= 0;j--){
77
+                t[i] +=array[i].substring(j,j+1);
78
+            }
79
+        }
80
+    
81
+        return t;
54
     }
82
     }
55
 
83
 
56
     /**
84
     /**
58
      * @return true if the order of the array is the same backwards and forwards
86
      * @return true if the order of the array is the same backwards and forwards
59
      */ // TODO
87
      */ // TODO
60
     public static boolean isPalindromic(String[] array) {
88
     public static boolean isPalindromic(String[] array) {
89
+        String length = array.length;
90
+        
91
+        for(int i = 0;i<length;i++){
92
+            String start = array[0];
93
+            String end = array[length];
94
+        }
95
+        
61
         return false;
96
         return false;
62
     }
97
     }
63
 
98
 

+ 42
- 0
package.bluej Ver fichero

1
+#BlueJ package file
2
+dependency1.from=StringArrayUtilsTest
3
+dependency1.to=StringArrayUtils
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=685
6
+editor.fx.0.width=1199
7
+editor.fx.0.x=50
8
+editor.fx.0.y=27
9
+objectbench.height=102
10
+objectbench.width=461
11
+package.divider.horizontal=0.6
12
+package.divider.vertical=0.7988929889298892
13
+package.editor.height=426
14
+package.editor.width=674
15
+package.editor.x=20
16
+package.editor.y=43
17
+package.frame.height=600
18
+package.frame.width=800
19
+package.numDependencies=1
20
+package.numTargets=2
21
+package.showExtends=true
22
+package.showUses=true
23
+project.charset=UTF-8
24
+readme.height=58
25
+readme.name=@README
26
+readme.width=47
27
+readme.x=10
28
+readme.y=10
29
+target1.height=50
30
+target1.name=StringArrayUtilsTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=150
34
+target1.x=130
35
+target1.y=10
36
+target2.height=50
37
+target2.name=StringArrayUtils
38
+target2.showInterface=false
39
+target2.type=ClassTarget
40
+target2.width=120
41
+target2.x=70
42
+target2.y=70