Преглед изворни кода

Merge bdd1cfbca128650093dcb13cb58ac32cfea57614 into b2e20fd406b12d4908e4fb952d821a476dd96c45

Peteyocre пре 6 година
родитељ
комит
2097f13c87
No account linked to committer's email

+ 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_9" project-jdk-name="9.0" 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>

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

@@ -9,17 +9,19 @@ public class ArrayDrills {
9 9
      * example : firstLast(6, [1,2,6); // Should return true
10 10
      *           firstLast(6, [1,2,3]); // Should return false
11 11
      */
12
-    public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
14
-    }
12
+    public Boolean firstLast(Integer value, Integer[] input) {
15 13
 
14
+        if (value.equals(input[0]) || value.equals(input[input.length - 1])) return true;
15
+        return false;
16
+    }
16 17
     /**
17 18
      * 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 19
      * example : sameFirstLast([1,2,3]); // Should return false
19 20
      *           sameFirstLast([1,2,1]); // Should return true
20 21
      */
21
-    public Boolean sameFirstLast(Integer[] input){
22
-        return null;
22
+    public Boolean sameFirstLast(Integer[] input) {
23
+        if (input.length > 1 && input[0] == input[input.length - 1]) return true;
24
+        return false;
23 25
     }
24 26
 
25 27
 
@@ -30,7 +32,8 @@ public class ArrayDrills {
30 32
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 33
      */
32 34
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
35
+        if (input1[0].equals(input2[0]) || input1[input1.length-1].equals(input2[input2.length-1])) return true;
36
+        return false;
34 37
     }
35 38
 
36 39
     /**
@@ -39,18 +42,39 @@ public class ArrayDrills {
39 42
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 43
      */
41 44
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
45
+        Integer[] newArray = new Integer[input.length];
46
+        for (int i = 0; i < input.length; i++) {
47
+            if (i == 0) newArray[2] = input[i];
48
+            else if  (i == 1) newArray[0] = input[i];
49
+            else if (i ==2) newArray[1] = input[i];
50
+        } return newArray;
43 51
     }
44 52
 
45 53
 
46 54
     /**
47
-     * Given an array of ints, figure out which is element in the array is largest,
55
+     * Given an array of ints, figure out which element in the array is largest,
48 56
      * and set all the other elements to be that value. Return the changed array.
49 57
      * example : maxValue([1, 2, 3]); // Should return [3,3,3]
50 58
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 59
      */
52 60
     public Integer[] maxValue(Integer[] input){
53
-        return null;
61
+
62
+        Integer[] maxValueArray = new Integer[input.length];
63
+        int currentMaxValue = 0;
64
+        int currentValue;
65
+
66
+        for(int i =0; i < input.length; i++ ) {
67
+           currentValue = input[i];
68
+            if (currentValue > currentMaxValue) {
69
+                currentMaxValue = currentValue;
70
+            }
71
+        }
72
+
73
+        for (int j =0; j < input.length; j++) {
74
+            maxValueArray[j] = currentMaxValue;
75
+        }
76
+
77
+        return maxValueArray;
54 78
     }
55 79
 
56 80
 
@@ -61,7 +85,21 @@ public class ArrayDrills {
61 85
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 86
      */
63 87
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
88
+        Integer[] newArray = new Integer[2];
89
+
90
+        newArray[0] = middleWayHelp(input1);
91
+        newArray[1] = middleWayHelp(input2);
92
+        return newArray;
93
+    }
94
+    public Integer middleWayHelp (Integer[] input) {
95
+
96
+        int middleElements;
97
+        if (input.length % 2 == 0)
98
+            middleElements = input[(Math.round(input.length/2))] + (input[(Math.round(input.length/2) -1)]);
99
+        else middleElements = input[Math.round(input.length/2)];
100
+
101
+        return middleElements;
102
+
65 103
     }
66 104
 
67 105
 
@@ -71,7 +109,12 @@ public class ArrayDrills {
71 109
      * Return the array which has the largest sum. In event of a tie, return a.
72 110
      */
73 111
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
112
+        int sumOfA = a[0] +a[1];
113
+        int sumOfB = b[0] + b[1];
114
+
115
+        if (sumOfA >= sumOfB) return a;
116
+        else return b;
117
+
75 118
     }
76 119
 
77 120
     /**
@@ -81,6 +124,8 @@ public class ArrayDrills {
81 124
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 125
      */
83 126
     public Integer[] midThree(Integer[] nums){
84
-        return null;
127
+        int length = nums.length;
128
+        Integer[] newArray = {nums[(length/2 -1)], nums[length/2], nums[(length/2 +1)]};
129
+        return newArray;
85 130
     }
86 131
 }

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

@@ -1,6 +1,5 @@
1 1
 package io.zipcoder;
2 2
 
3
-import com.sun.tools.corba.se.idl.InterfaceGen;
4 3
 import org.junit.Assert;
5 4
 import org.junit.Before;
6 5
 import org.junit.Test;
@@ -179,7 +178,7 @@ public class ArrayDrillsTest {
179 178
     public void biggerTwo3(){
180 179
         Integer[] inputArray1 = {-1 ,20};
181 180
         Integer[] inputArray2 = {2, 15};
182
-        Integer[] expected = {1,20};
181
+        Integer[] expected = {-1,20};
183 182
         Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
184 183
         Assert.assertArrayEquals(expected, actual);
185 184
     }

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


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