BlackJack пре 6 година
родитељ
комит
7373304707

+ 1
- 0
.idea/.name Прегледај датотеку

@@ -0,0 +1 @@
1
+FundamentalDrills-Part1

+ 16
- 0
.idea/compiler.xml Прегледај датотеку

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <annotationProcessing>
5
+      <profile name="Maven default annotation processors profile" enabled="true">
6
+        <sourceOutputDir name="target/generated-sources/annotations" />
7
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8
+        <outputRelativeToContentRoot value="true" />
9
+        <module name="FundamentalDrills-Part1" />
10
+      </profile>
11
+    </annotationProcessing>
12
+    <bytecodeTargetLevel>
13
+      <module name="FundamentalDrills-Part1" target="1.5" />
14
+    </bytecodeTargetLevel>
15
+  </component>
16
+</project>

+ 13
- 0
.idea/misc.xml Прегледај датотеку

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="MavenProjectsManager">
4
+    <option name="originalFiles">
5
+      <list>
6
+        <option value="$PROJECT_DIR$/pom.xml" />
7
+      </list>
8
+    </option>
9
+  </component>
10
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
11
+    <output url="file://$PROJECT_DIR$/classes" />
12
+  </component>
13
+</project>

+ 8
- 0
.idea/modules.xml Прегледај датотеку

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/FundamentalDrills-Part1.iml" filepath="$PROJECT_DIR$/FundamentalDrills-Part1.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs.xml Прегледај датотеку

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+  </component>
6
+</project>

+ 16
- 0
FundamentalDrills-Part1.iml Прегледај датотеку

@@ -0,0 +1,16 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
4
+    <output url="file://$MODULE_DIR$/target/classes" />
5
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
6
+    <content url="file://$MODULE_DIR$">
7
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+      <excludeFolder url="file://$MODULE_DIR$/target" />
10
+    </content>
11
+    <orderEntry type="inheritedJdk" />
12
+    <orderEntry type="sourceFolder" forTests="false" />
13
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
14
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
15
+  </component>
16
+</module>


BIN
src/main/.DS_Store Прегледај датотеку


BIN
src/main/java/.DS_Store Прегледај датотеку


BIN
src/main/java/io/.DS_Store Прегледај датотеку


+ 109
- 24
src/main/java/io/zipcoder/ArrayDrills.java Прегледај датотеку

@@ -1,5 +1,8 @@
1 1
 package io.zipcoder;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
3 6
 public class ArrayDrills {
4 7
 
5 8
 
@@ -7,19 +10,29 @@ public class ArrayDrills {
7 10
      * Given an array of ints, return true if value appears as either the first or last element in the array.
8 11
      * The array will be length 1 or more.
9 12
      * example : firstLast(6, [1,2,6); // Should return true
10
-     *           firstLast(6, [1,2,3]); // Should return false
13
+     * firstLast(6, [1,2,3]); // Should return false
11 14
      */
12
-    public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
15
+    public Boolean firstLast(Integer value, Integer[] input) {
16
+
17
+
18
+        if (value.equals(input[input.length - 1]) || value.equals(input[0])) return true;
19
+
20
+        else return false;
21
+
22
+
14 23
     }
15 24
 
25
+
16 26
     /**
17 27
      * Given an array of ints, return true if the array is length 1 or more, and the first element and the last element are equal.
18 28
      * example : sameFirstLast([1,2,3]); // Should return false
19
-     *           sameFirstLast([1,2,1]); // Should return true
29
+     * sameFirstLast([1,2,1]); // Should return true
20 30
      */
21
-    public Boolean sameFirstLast(Integer[] input){
22
-        return null;
31
+    public Boolean sameFirstLast(Integer[] input) {
32
+        if (input.length > 1 && input[0].equals(input[input.length - 1])) return true;
33
+        else return false;
34
+
35
+
23 36
     }
24 37
 
25 38
 
@@ -27,19 +40,29 @@ public class ArrayDrills {
27 40
      * Given 2 arrays of ints, a and b, return true if they have the same first element or they have the same last element.
28 41
      * Both arrays will be length 1 or more.
29 42
      * example : commonEnd([1, 2, 3], [7, 3]); // Should return true
30
-     *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
43
+     * commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 44
      */
32
-    public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
45
+    public Boolean commonEnd(Integer[] input1, Integer[] input2) {
46
+        if (input1[0].equals(input2[0]) || input1[input1.length - 1].equals(input2[input2.length - 1])) return true;
47
+        else return false;
48
+
34 49
     }
35 50
 
36 51
     /**
37 52
      * Given an array of ints, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}.
38 53
      * example : rotateLeft([1, 2, 3]); // Should return [2,3,1]
39
-     *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
54
+     * rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 55
      */
41
-    public Integer[] rotateLeft(Integer[] input){
42
-        return null;
56
+    public Integer[] rotateLeft(Integer[] input) {
57
+        Integer temp = input[0];
58
+
59
+        Integer[] newArr = new Integer[input.length];
60
+        for (int x = 0; x < input.length - 1; x++) {
61
+            newArr[x] = input[x + 1];
62
+        }
63
+        newArr[input.length - 1] = temp;
64
+
65
+        return newArr;
43 66
     }
44 67
 
45 68
 
@@ -47,10 +70,26 @@ public class ArrayDrills {
47 70
      * Given an array of ints, figure out which is element in the array is largest,
48 71
      * and set all the other elements to be that value. Return the changed array.
49 72
      * example : maxValue([1, 2, 3]); // Should return [3,3,3]
50
-     *           maxValue([5, 11, 9]); // Should return [11,11,11]
73
+     * maxValue([5, 11, 9]); // Should return [11,11,11]
51 74
      */
52
-    public Integer[] maxValue(Integer[] input){
53
-        return null;
75
+    public Integer[] maxValue(Integer[] input) {
76
+        Integer temp = input[0];
77
+
78
+        Integer[] newArr = new Integer[input.length];
79
+        for (Integer x = 0; x < input.length; x++) {
80
+
81
+            if (input[x] > temp) {
82
+                temp = input[x];
83
+
84
+            }
85
+
86
+        }
87
+        for (Integer z = 0; z < newArr.length; z++) {
88
+
89
+            newArr[z] = temp;
90
+        }
91
+        return newArr;
92
+
54 93
     }
55 94
 
56 95
 
@@ -58,10 +97,28 @@ public class ArrayDrills {
58 97
      * Given 2 int arrays, a and b, return a new array length 2 containing their middle elements, if length is odd.
59 98
      * If the array length is even the sum of the middle 2 elements in the array.
60 99
      * example : middleWay([1, 2, 3], [4,5,6,2]); // Should return [2,11]
61
-     *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
100
+     * middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 101
      */
63
-    public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
102
+    public Integer[] middleWay(Integer[] input1, Integer[] input2) {
103
+        Integer[] newArr = new Integer[2];
104
+        newArr[0] = mid(input1);
105
+        newArr[1] = mid(input2);
106
+
107
+        return newArr;
108
+
109
+    }
110
+
111
+    public Integer mid(Integer[] input) {
112
+        int value = 0;
113
+        if (input.length % 2 == 0) {
114
+            value = input[input.length / 2] + input[(input.length / 2) - 1];
115
+
116
+        } else {
117
+            value = input[input.length / 2];
118
+
119
+        }
120
+
121
+        return value;
65 122
     }
66 123
 
67 124
 
@@ -70,17 +127,45 @@ public class ArrayDrills {
70 127
      * Consider the sum of the values in each array.
71 128
      * Return the array which has the largest sum. In event of a tie, return a.
72 129
      */
73
-    public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
130
+    public Integer[] biggerTwo(Integer[] a, Integer[] b) {
131
+
132
+        int count1 = 0;
133
+        for (int x = 0; x < a.length; x++) {
134
+            count1 += a[x];
135
+        }
136
+
137
+        int count2 = 0;
138
+        for (int z = 0; z < b.length; z++) {
139
+            count2 += b[z];
140
+        }
141
+
142
+        if (count1 <= count2) {
143
+            return b;
144
+        } else {
145
+            return a;
146
+        }
147
+
148
+        //return null;
75 149
     }
76 150
 
151
+
77 152
     /**
78 153
      * Given an array of ints of odd length, return a new array length 3 containing the elements from the middle of the array.
79 154
      * The array length will be at least 3.
80 155
      * example : midThree([1, 2, 3, 4, 5]); // Should return [2, 3, 4]
81
-     *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
156
+     * midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 157
      */
83
-    public Integer[] midThree(Integer[] nums){
84
-        return null;
158
+    public Integer[] midThree(Integer[] nums) {
159
+        Integer[] newArr = new Integer[3];
160
+        Integer x = nums.length /2;
161
+
162
+
163
+            newArr[0] = nums[x - 1];
164
+            newArr[1] = nums[x];
165
+            newArr[2] = nums[x + 1];
166
+
167
+        return newArr;
168
+        }
169
+
85 170
     }
86
-}
171
+

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java Прегледај датотеку

@@ -179,7 +179,7 @@ public class ArrayDrillsTest {
179 179
     public void biggerTwo3(){
180 180
         Integer[] inputArray1 = {-1 ,20};
181 181
         Integer[] inputArray2 = {2, 15};
182
-        Integer[] expected = {1,20};
182
+        Integer[] expected = {-1,20};
183 183
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
184 184
         Assert.assertArrayEquals(expected, actual);
185 185
     }

BIN
target/classes/io/zipcoder/ArrayDrills.class Прегледај датотеку


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class Прегледај датотеку