Ver código fonte

...almost done

Katrice Williams-Dredden 6 anos atrás
pai
commit
93dc6ca0a9

+ 16
- 0
.idea/compiler.xml Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

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

+ 46
- 6
src/main/java/io/zipcoder/ArrayDrills.java Ver arquivo

@@ -10,16 +10,21 @@ public class ArrayDrills {
10 10
      *           firstLast(6, [1,2,3]); // Should return false
11 11
      */
12 12
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
13
+        if(value.equals(input[0])||value.equals(input[input.length-1])){
14
+            return true;
15
+            }
16
+        return false;
14 17
     }
15 18
 
19
+
16 20
     /**
17 21
      * 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 22
      * example : sameFirstLast([1,2,3]); // Should return false
19 23
      *           sameFirstLast([1,2,1]); // Should return true
20 24
      */
21 25
     public Boolean sameFirstLast(Integer[] input){
22
-        return null;
26
+        return (input.length>=1 && input[0 ].equals(input[input.length-1]));
27
+
23 28
     }
24 29
 
25 30
 
@@ -30,7 +35,8 @@ public class ArrayDrills {
30 35
      *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31 36
      */
32 37
     public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
-        return null;
38
+        return (input1[0].equals(input2[0])||input1[input1.length-1].equals(input2[input2.length-1]));
39
+
34 40
     }
35 41
 
36 42
     /**
@@ -39,7 +45,14 @@ public class ArrayDrills {
39 45
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 46
      */
41 47
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
48
+        //review notes in book of break down
49
+        Integer[] rotatedArray = new Integer[input.length];
50
+        rotatedArray[rotatedArray.length - 1] = input[0];
51
+
52
+        for(Integer i = 0; i<rotatedArray.length-1;i++){
53
+            rotatedArray[i]=input[i+1];
54
+        }
55
+        return rotatedArray;
43 56
     }
44 57
 
45 58
 
@@ -50,6 +63,16 @@ public class ArrayDrills {
50 63
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 64
      */
52 65
     public Integer[] maxValue(Integer[] input){
66
+        //halfway done, don't really understand what I'm doing wrong here.
67
+        Integer[] array2 = new Integer[3];
68
+
69
+        Integer temporary = input[0];
70
+        for(Integer i =1; i<input.length;i++){
71
+            if(temporary<input[i]){
72
+                temporary=input[i];
73
+
74
+            }
75
+        }
53 76
         return null;
54 77
     }
55 78
 
@@ -61,6 +84,8 @@ public class ArrayDrills {
61 84
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 85
      */
63 86
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
87
+
88
+
64 89
         return null;
65 90
     }
66 91
 
@@ -71,7 +96,13 @@ public class ArrayDrills {
71 96
      * Return the array which has the largest sum. In event of a tie, return a.
72 97
      */
73 98
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
99
+        Integer addUp = a[0]+a[1];
100
+        Integer addUp1 = b[0]+b[1];
101
+
102
+        if(addUp>addUp1){
103
+            return a;
104
+        }
105
+        return b;
75 106
     }
76 107
 
77 108
     /**
@@ -81,6 +112,15 @@ public class ArrayDrills {
81 112
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 113
      */
83 114
     public Integer[] midThree(Integer[] nums){
84
-        return null;
115
+
116
+        Integer[] array2 = new Integer[3];
117
+
118
+        Integer a = nums.length;
119
+        Integer middleIndex = nums.length / 2;
120
+        array2[0] = nums[middleIndex-1];
121
+        array2[1] = nums[middleIndex];
122
+        array2[2] = nums[middleIndex+1];
123
+
124
+        return array2;
85 125
     }
86 126
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java Ver arquivo

@@ -1,6 +1,6 @@
1 1
 package io.zipcoder;
2 2
 
3
-import com.sun.tools.corba.se.idl.InterfaceGen;
3
+
4 4
 import org.junit.Assert;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;

BIN
target/classes/io/zipcoder/ArrayDrills.class Ver arquivo


BIN
target/test-classes/io/zipcoder/ArrayDrillsTest.class Ver arquivo