Aleena Rose-Mathew 6 gadus atpakaļ
vecāks
revīzija
123f0e5019

+ 1
- 0
.idea/.name Parādīt failu

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

+ 16
- 0
.idea/compiler.xml Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

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

+ 95
- 8
src/main/java/io/zipcoder/ArrayDrills.java Parādīt failu

@@ -1,5 +1,7 @@
1 1
 package io.zipcoder;
2 2
 
3
+import com.sun.media.sound.SoftMixingMixerProvider;
4
+
3 5
 public class ArrayDrills {
4 6
 
5 7
 
@@ -10,7 +12,12 @@ public class ArrayDrills {
10 12
      *           firstLast(6, [1,2,3]); // Should return false
11 13
      */
12 14
     public Boolean firstLast(Integer value, Integer[] input){
13
-        return null;
15
+        if(input[0]==value ||input[input.length-1]==value)
16
+        {
17
+            return true;
18
+        }
19
+
20
+        return false;
14 21
     }
15 22
 
16 23
     /**
@@ -19,7 +26,11 @@ public class ArrayDrills {
19 26
      *           sameFirstLast([1,2,1]); // Should return true
20 27
      */
21 28
     public Boolean sameFirstLast(Integer[] input){
22
-        return null;
29
+        if(input.length!=0&&input[0]==input[input.length-1])
30
+        {
31
+            return true;
32
+        }
33
+        return false;
23 34
     }
24 35
 
25 36
 
@@ -30,7 +41,11 @@ 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]||input1[input1.length-1]==input2[input2.length-1])
45
+        {
46
+            return true;
47
+        }
48
+        return false;
34 49
     }
35 50
 
36 51
     /**
@@ -39,7 +54,15 @@ public class ArrayDrills {
39 54
      *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40 55
      */
41 56
     public Integer[] rotateLeft(Integer[] input){
42
-        return null;
57
+        Integer[] newArray=new Integer[input.length];
58
+
59
+
60
+        for(int i=0;i<input.length-1;i++)
61
+        {
62
+            newArray[i]=input[i+1];
63
+        }
64
+        newArray[input.length-1]=input[0];
65
+        return newArray;
43 66
     }
44 67
 
45 68
 
@@ -50,7 +73,20 @@ public class ArrayDrills {
50 73
      *           maxValue([5, 11, 9]); // Should return [11,11,11]
51 74
      */
52 75
     public Integer[] maxValue(Integer[] input){
53
-        return null;
76
+        int max=0;
77
+        Integer[] newArray =new Integer[input.length];
78
+        for (int i=0;i<input.length;i++)
79
+        {
80
+            if(input[i]>max)
81
+            {
82
+                max=input[i];
83
+            }
84
+        }
85
+        for (int i=0;i<input.length;i++)
86
+        {
87
+            newArray[i]=max;
88
+        }
89
+        return newArray;
54 90
     }
55 91
 
56 92
 
@@ -61,7 +97,28 @@ public class ArrayDrills {
61 97
      *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62 98
      */
63 99
     public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
-        return null;
100
+        Integer[] newArray=new Integer[2];
101
+        int len1=input1.length;
102
+        int len2=input2.length;
103
+        if(len1%2!=0)//odd input1
104
+        {
105
+            newArray[0]=input1[len1/2];
106
+
107
+
108
+        }
109
+        else//even input1
110
+        {
111
+            newArray[0]=input1[(len1-1)/2]+input1[len1/2];
112
+        }
113
+        if(len2%2!=0)//odd
114
+        {
115
+            newArray[1]=input2[len2/2];
116
+        }
117
+        else
118
+        {
119
+            newArray[1]=input2[(len2-1)/2]+input2[(len2/2)];
120
+        }
121
+        return newArray;
65 122
     }
66 123
 
67 124
 
@@ -71,7 +128,24 @@ public class ArrayDrills {
71 128
      * Return the array which has the largest sum. In event of a tie, return a.
72 129
      */
73 130
     public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
-        return null;
131
+        int sum1=0;
132
+        int sum2=0;
133
+
134
+        for(int i=0;i<a.length;i++)
135
+        {
136
+            sum1=sum1+a[i];
137
+            sum2=sum2+b[i];
138
+        }
139
+        if(sum1==sum2)
140
+        {
141
+            return a;
142
+        }
143
+        else if(sum1>sum2)
144
+        {
145
+            return a;
146
+        }
147
+
148
+        return b;
75 149
     }
76 150
 
77 151
     /**
@@ -81,6 +155,19 @@ public class ArrayDrills {
81 155
      *           midThree([8, 6, 7, 5, 3, 0, 9]); // Should return [7, 5, 3]
82 156
      */
83 157
     public Integer[] midThree(Integer[] nums){
84
-        return null;
158
+        Integer[] newArray= new Integer[3];
159
+        int len=nums.length;
160
+        int mid=len/2;
161
+
162
+
163
+            newArray[0]=nums[mid-1];
164
+            newArray[1]=nums[mid];
165
+            newArray[2]=nums[mid+1];
166
+
167
+
168
+
169
+
170
+        System.out.println(newArray);
171
+        return newArray;
85 172
     }
86 173
 }

+ 1
- 1
src/test/java/io/zipcoder/ArrayDrillsTest.java Parādīt failu

@@ -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ārs
target/classes/io/zipcoder/ArrayDrills.class Parādīt failu


Binārs
target/test-classes/io/zipcoder/ArrayDrillsTest.class Parādīt failu