Browse Source

all tests pass

Allison Ziegler 6 years ago
parent
commit
857a2397fa

+ 1
- 0
.idea/.name View File

1
+FundamentalDrills-Part1

+ 16
- 0
.idea/compiler.xml View File

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 View File

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 View File

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 View File

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 View File

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>

+ 51
- 9
src/main/java/io/zipcoder/ArrayDrills.java View File

1
 package io.zipcoder;
1
 package io.zipcoder;
2
 
2
 
3
+import java.util.Arrays;
4
+
3
 public class ArrayDrills {
5
 public class ArrayDrills {
4
 
6
 
5
 
7
 
10
      *           firstLast(6, [1,2,3]); // Should return false
12
      *           firstLast(6, [1,2,3]); // Should return false
11
      */
13
      */
12
     public Boolean firstLast(Integer value, Integer[] input){
14
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
15
+
16
+        if (input[0] == value || input[input.length - 1] == value) {
17
+            return true;
18
+        }
19
+        return false;
14
     }
20
     }
15
 
21
 
16
     /**
22
     /**
19
      *           sameFirstLast([1,2,1]); // Should return true
25
      *           sameFirstLast([1,2,1]); // Should return true
20
      */
26
      */
21
     public Boolean sameFirstLast(Integer[] input){
27
     public Boolean sameFirstLast(Integer[] input){
22
-        return null;
28
+        if (input [0] == input[input.length - 1]){
29
+            return true;
30
+        }
31
+        else return false;
23
     }
32
     }
24
 
33
 
25
 
34
 
30
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
39
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31
      */
40
      */
32
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
41
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
42
+        if (input1[0] == input2[0] || input1[input1.length -1] == input2[input2.length - 1]) {
43
+            return true;
44
+        }
45
+        else return false;
34
     }
46
     }
35
 
47
 
36
     /**
48
     /**
39
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
51
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40
      */
52
      */
41
     public Integer[] rotateLeft(Integer[] input){
53
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
54
+        Integer nextValue = input[0];
55
+        for (int i = input.length - 1; i >= 0; i--) {
56
+            Integer temp = input[i];
57
+            input[i] = nextValue;
58
+            nextValue = temp;
59
+        }
60
+        return input;
43
     }
61
     }
44
 
62
 
45
 
63
 
50
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
68
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51
      */
69
      */
52
     public Integer[] maxValue(Integer[] input){
70
     public Integer[] maxValue(Integer[] input){
53
-        return null;
71
+        Integer maxValue = null;
72
+        for (Integer x : input) {
73
+            if (maxValue == null || x > maxValue) {
74
+                maxValue = x;
75
+            }
76
+        }
77
+        for (int i = 0; i < input.length; i++){
78
+            input[i] = maxValue;
79
+        }
80
+        return input;
54
     }
81
     }
55
 
82
 
56
 
83
 
61
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
88
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62
      */
89
      */
63
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
90
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
91
+        Integer[] returnArr = new Integer[2];
92
+        returnArr[0] = getMiddleValue(input1);
93
+        returnArr[1] = getMiddleValue(input2);
94
+        return returnArr;
95
+    }
96
+    private Integer getMiddleValue(Integer[] input) {
97
+        if (input.length % 2 == 0) {
98
+            return input[input.length/2] + input[(input.length/2) - 1];
99
+        }
100
+        else return input[input.length/2];
65
     }
101
     }
66
-
67
 
102
 
68
     /**
103
     /**
69
      * Start with 2 int arrays, a and b, each length 2.
104
      * Start with 2 int arrays, a and b, each length 2.
71
      * Return the array which has the largest sum. In event of a tie, return a.
106
      * Return the array which has the largest sum. In event of a tie, return a.
72
      */
107
      */
73
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
108
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
109
+        if (a[0] + a[1] >= b[0] + b[1]) {
110
+            return a;
111
+        }
112
+        else return b;
75
     }
113
     }
76
 
114
 
77
     /**
115
     /**
81
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
119
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82
      */
120
      */
83
     public Integer[] midThree(Integer[] nums){
121
     public Integer[] midThree(Integer[] nums){
84
-        return null;
122
+        Integer[] midThree = new Integer[3];
123
+        midThree[0] = nums[nums.length/2 - 1];
124
+        midThree[1] = nums[nums.length/2];
125
+        midThree[2] = nums[nums.length/2 + 1];
126
+        return midThree;
85
     }
127
     }
86
 }
128
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java View File

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

BIN
target/classes/io/zipcoder/ArrayDrills.class View File


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class View File