April Rivera před 6 roky
rodič
revize
aacf3566a9

+ 16
- 0
.idea/compiler.xml Zobrazit soubor

@@ -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 target="1.8">
13
+      <module name="FundamentalDrills-Part1" target="1.8" />
14
+    </bytecodeTargetLevel>
15
+  </component>
16
+</project>

+ 13
- 0
.idea/misc.xml Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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_8">
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>

+ 12
- 0
pom.xml Zobrazit soubor

@@ -7,6 +7,18 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>FundamentalDrills-Part1</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <build>
11
+        <plugins>
12
+            <plugin>
13
+                <groupId>org.apache.maven.plugins</groupId>
14
+                <artifactId>maven-compiler-plugin</artifactId>
15
+                <configuration>
16
+                    <source>1.8</source>
17
+                    <target>1.8</target>
18
+                </configuration>
19
+            </plugin>
20
+        </plugins>
21
+    </build>
10 22
 
11 23
     <dependencies>
12 24
         <dependency>

+ 60
- 9
src/main/java/io/zipcoder/ArrayDrills.java Zobrazit soubor

@@ -1,5 +1,10 @@
1 1
 package io.zipcoder;
2 2
 
3
+import com.sun.tools.corba.se.idl.InterfaceGen;
4
+
5
+import java.util.Arrays;
6
+
7
+
3 8
 public class ArrayDrills {
4 9
 
5 10
 
@@ -10,7 +15,10 @@ public class ArrayDrills {
10 15
      *           firstLast(6, [1,2,3]); // Should return false
11 16
      */
12 17
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
18
+        if(value.equals(input[0]) || value.equals(input[input.length - 1])){
19
+            return true;
20
+        }
21
+        else return false;
14 22
     }
15 23
 
16 24
     /**
@@ -18,8 +26,11 @@ public class ArrayDrills {
18 26
      * example : sameFirstLast([1,2,3]); // Should return false
19 27
      *           sameFirstLast([1,2,1]); // Should return true
20 28
      */
21
-    public Boolean sameFirstLast(Integer[] input){
22
-        return null;
29
+    public Boolean sameFirstLast(Integer[] input) {
30
+        if (input.length >= 1 && input[0] == input[input.length - 1]) {
31
+            return true;
32
+        }
33
+        else return false;
23 34
     }
24 35
 
25 36
 
@@ -30,7 +41,13 @@ public class ArrayDrills {
30 41
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 42
      */
32 43
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
44
+         if(input1[0] == input2[0]){
45
+             return true;
46
+         }
47
+         else if(input1[input1.length - 1] == input2[input2.length - 1]){
48
+             return true;
49
+         }
50
+             else return false;
34 51
     }
35 52
 
36 53
     /**
@@ -39,7 +56,8 @@ public class ArrayDrills {
39 56
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 57
      */
41 58
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
59
+        Integer[] newArray = {input[1], input[2], input[0]};
60
+        return newArray;
43 61
     }
44 62
 
45 63
 
@@ -50,7 +68,17 @@ public class ArrayDrills {
50 68
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 69
      */
52 70
     public Integer[] maxValue(Integer[] input){
53
-        return null;
71
+        Integer[] newArray = new Integer[input.length];
72
+        int max;
73
+        max = input[0];
74
+
75
+        for(int value : input){
76
+            if(value > max){
77
+                max = value;
78
+            }
79
+            }
80
+        Arrays.fill(newArray,max);
81
+        return newArray;
54 82
     }
55 83
 
56 84
 
@@ -61,7 +89,20 @@ public class ArrayDrills {
61 89
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 90
      */
63 91
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
92
+        Integer[] newArr = new Integer[2];
93
+        int half1 = input1.length/2;
94
+        int half2 = input2.length/2;
95
+
96
+        if(input1.length % 2 == 0){
97
+            newArr[0]= input1[half1-1] + input1[half1];
98
+        }
99
+        else newArr[0] = input1[half1];
100
+
101
+        if(input2.length % 2 == 0){
102
+            newArr[1] = input2[half2-1] + input2[half2];
103
+        }
104
+        else newArr[1] = input2[half2];
105
+        return newArr;
65 106
     }
66 107
 
67 108
 
@@ -70,8 +111,12 @@ public class ArrayDrills {
70 111
      * Consider the sum of the values in each array.
71 112
      * Return the array which has the largest sum. In event of a tie, return a.
72 113
      */
114
+    //Was test supposed to have -1? Changed it already btw
73 115
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
116
+        if(a[0] + a[1] > b[0] + b[1]){
117
+            return a;
118
+        }
119
+        else return b;
75 120
     }
76 121
 
77 122
     /**
@@ -81,6 +126,12 @@ public class ArrayDrills {
81 126
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 127
      */
83 128
     public Integer[] midThree(Integer[] nums){
84
-        return null;
129
+        Integer[] newArr = new Integer[3];
130
+        int half = nums.length/2;
131
+        newArr[0] = nums[half - 1];
132
+        newArr[1] = nums[half];
133
+        newArr[2] = nums[half+1];
134
+        return newArr;
85 135
     }
136
+
86 137
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java Zobrazit soubor

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

binární
target/classes/io/zipcoder/ArrayDrills.class Zobrazit soubor


binární
target/test-classes/io/zipcoder/ArrayDrillsTest.class Zobrazit soubor