Simran Bhutani 5 年之前
父節點
當前提交
5365cc63df

+ 8
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java 查看文件

@@ -1,10 +1,17 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class SquareArrayAnalyzer {
7 9
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
10
+        if (input == null || squaredValues == null) return false;
11
+        if (input.length != squaredValues.length) return false;
12
+
13
+        Object[] sortedA = Arrays.stream(input).map(x -> x*x).sorted().toArray();
14
+        Object[] sortedB = Arrays.stream(squaredValues).sorted().toArray();
15
+        return Arrays.equals(sortedA, sortedB);
9 16
     }
10 17
 }

+ 22
- 2
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java 查看文件

@@ -5,11 +5,17 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class TicTacToe {
7 7
 
8
+    private final String[][] board;
9
+
8 10
     public TicTacToe(String[][] board) {
11
+        this.board= board;
12
+
9 13
     }
10 14
 
11 15
     public String[] getRow(Integer value) {
16
+
12 17
         return null;
18
+
13 19
     }
14 20
 
15 21
     public String[] getColumn(Integer value) {
@@ -17,14 +23,28 @@ public class TicTacToe {
17 23
     }
18 24
 
19 25
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
26
+
27
+        for(int i=0;i<rowIndex;i++){
28
+            return true;
29
+        }
30
+        return true;
31
+
32
+
21 33
     }
22 34
 
23 35
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
36
+
37
+
38
+        for(int i=0;i<columnIndex;i++){
39
+            return true;
40
+        }
41
+        return true;
25 42
     }
26 43
 
27 44
     public String getWinner() {
45
+
46
+
47
+
28 48
         return null;
29 49
     }
30 50
 }

+ 22
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java 查看文件

@@ -5,6 +5,27 @@ package rocks.zipcode.io.quiz3.arrays;
5 5
  */
6 6
 public class WaveGenerator {
7 7
     public static String[] wave(String str) {
8
-        return null;
8
+        String word= str.toLowerCase();
9
+        char[] charword= word.toCharArray();
10
+        int length= charword.length;
11
+        int counter=0;
12
+        String result="";
13
+        String a="";
14
+        for(int i=0;i<length;i++){
15
+            for(int j=0;j<length;j++){
16
+                if(counter==j){
17
+                    char charupper= Character.toUpperCase(charword[j]);
18
+                    result= result+ Character.toString(charupper);
19
+                }
20
+                else{
21
+                    result=result+ Character.toString(charword[j]);
22
+                }
23
+            }
24
+            result= result +", ";
25
+             a = result.substring(0, result.lastIndexOf(","));
26
+            counter ++;
27
+        }
28
+
29
+        return new String[]{a.trim()};
9 30
     }
10 31
 }

+ 46
- 5
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java 查看文件

@@ -1,24 +1,65 @@
1 1
 package rocks.zipcode.io.quiz3.collections;
2 2
 
3
+import java.util.Objects;
4
+
3 5
 /**
4 6
  * @author leon on 10/12/2018.
5 7
  */
6 8
 public class Lab {
7
-    public Lab() {
8
-        this(null);
9
-    }
9
+    private  String labName;
10
+    private String name;
11
+    private String labStatus;
12
+
13
+//    public Lab() {
14
+//        this(null);
15
+//    }
10 16
 
11 17
     public Lab(String labName) {
18
+        this.labName= labName;
12 19
     }
13 20
 
14 21
     public String getLabStatus() {
15
-        return null;
22
+        return labStatus;
16 23
     }
17 24
 
18 25
     public void setLabStatus(String labStatus) {
26
+        this.labStatus=labStatus;
19 27
     }
20 28
 
21 29
     public String getName() {
22
-        return null;
30
+
31
+        return name;
32
+    }
33
+
34
+    public void setLabName(String labName) {
35
+        this.labName = labName;
36
+    }
37
+
38
+    public void setName(String name) {
39
+        this.name = name;
40
+    }
41
+
42
+    @Override
43
+    public boolean equals(Object o) {
44
+        if (this == o) return true;
45
+        if (o == null || getClass() != o.getClass()) return false;
46
+        Lab lab = (Lab) o;
47
+        return Objects.equals(labName, lab.labName) &&
48
+                Objects.equals(name, lab.name) &&
49
+                Objects.equals(labStatus, lab.labStatus);
50
+    }
51
+
52
+    @Override
53
+    public int hashCode() {
54
+        return Objects.hash(labName, name, labStatus);
55
+    }
56
+
57
+    @Override
58
+    public String toString() {
59
+        return "Lab{" +
60
+                "labName='" + labName + '\'' +
61
+                ", name='" + name + '\'' +
62
+                ", labStatus='" + labStatus + '\'' +
63
+                '}';
23 64
     }
24 65
 }

+ 14
- 0
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java 查看文件

@@ -8,21 +8,35 @@ import java.util.Map;
8 8
  * @author leon on 10/12/2018.
9 9
  */
10 10
 public class Student {
11
+    private LabStatus labSatus;
12
+
11 13
     public Student() {
12 14
         this(null);
13 15
     }
14 16
 
15 17
     public Student(Map<Lab, LabStatus> map) {
18
+
16 19
     }
17 20
 
18 21
     public void setLabStatus(Lab lab, LabStatus labStatus) {
22
+        this.labSatus= labStatus;
19 23
     }
20 24
 
21 25
 
22 26
     public void forkLab(Lab lab) {
27
+
23 28
     }
24 29
 
25 30
     public LabStatus getLabStatus(String labName) {
26 31
         throw new UnsupportedOperationException("Method not yet implemented");
32
+
33
+    }
34
+
35
+
36
+    @Override
37
+    public String toString() {
38
+        return "Student{" +
39
+                "labSatus=" + labSatus +
40
+                '}';
27 41
     }
28 42
 }

+ 44
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java 查看文件

@@ -1,10 +1,53 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.Arrays;
4
+
5
+import static rocks.zipcode.io.quiz3.fundamentals.VowelUtils.isVowel;
6
+
3 7
 /**
4 8
  * @author leon on 09/12/2018.
5 9
  */
6 10
 public class PigLatinGenerator {
11
+
7 12
     public String translate(String str) {
8
-        return null;
13
+        int len = str.length();
14
+        int index = -1;
15
+        for (int i = 0; i < len; i++)
16
+        {
17
+            if (isVowel(str.charAt(i))) {
18
+                index = i;
19
+                break;
20
+            }
21
+        }
22
+
23
+        if (index == -1)
24
+            return "-1";
25
+
26
+        return str.substring(index) +
27
+                str.substring(0, index) + "ay";
28
+    }
29
+
30
+    static boolean isVowel(char c) {
31
+        return (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ||
32
+                c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
33
+    }
34
+
35
+    public static int findFirstVowel(String words) {
36
+        for (int i = 0; i < words.length(); i++) {
37
+            switch (words.charAt(i)) {
38
+                case 'a':
39
+                case 'e':
40
+                case 'i':
41
+                case 'o':
42
+                case 'u':
43
+                case 'A':
44
+                case 'E':
45
+                case 'I':
46
+                case 'O':
47
+                case 'U':
48
+                    return words.indexOf(i);
49
+            }
50
+        }
51
+        return -1;
9 52
     }
10 53
 }

+ 20
- 2
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java 查看文件

@@ -5,10 +5,28 @@ package rocks.zipcode.io.quiz3.fundamentals;
5 5
  */
6 6
 public class StringUtils {
7 7
     public static String capitalizeNthCharacter(String str, Integer indexToCapitalize) {
8
-        return null;
8
+
9
+
10
+        StringBuilder sb = new StringBuilder(str);
11
+        sb.setCharAt(indexToCapitalize , Character.toUpperCase(sb.charAt(indexToCapitalize+1)));
12
+        return (sb.toString());
13
+
14
+//        StringBuilder sb = new StringBuilder(str);
15
+//        while (indexToCapitalize < sb.length()) {
16
+////            sb.setCharAt(indexToCapitalize-1,Character.toUpperCase(sb.charAt(indexToCapitalize-1)));
17
+////            indexToCapitalize++;
18
+//
19
+//
20
+//        }
21
+//
22
+//        return sb.toString();
9 23
     }
10 24
 
11 25
     public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
26
+
27
+       if( baseString.charAt(indexOfString) == characterToCheckFor)
28
+
29
+        return true;
30
+       else return false;
13 31
     }
14 32
 }

+ 42
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java 查看文件

@@ -1,23 +1,62 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.regex.Pattern;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class VowelUtils {
7 9
     public static Boolean hasVowels(String word) {
8
-        return null;
10
+
11
+        String newword = word.toUpperCase();
12
+        char[] words = newword.toCharArray();
13
+        for(int i = 0; i<words.length; i++){
14
+            char z = words[i];
15
+            if (z=='A'||z=='E'||z=='I'||z=='O'||z=='U')
16
+                return true;
17
+        }
18
+        return false;
9 19
     }
10 20
 
21
+
22
+
11 23
     public static Integer getIndexOfFirstVowel(String word) {
24
+        final  String vowels = "aeiou";
25
+        String loweredWord = word.toLowerCase();
26
+
27
+        for (int index = 0; index < loweredWord.length(); index++)
28
+        {
29
+            if (vowels.contains(String.valueOf(loweredWord.charAt(index))))
30
+            {
31
+                return index;
32
+            }
33
+        }
12 34
         return null;
35
+
13 36
     }
14 37
 
15 38
 
16 39
     public static Boolean startsWithVowel(String word) {
17
-        return null;
40
+
41
+        if(word.startsWith("a") || word.startsWith("e") ||word.startsWith("i") || word.startsWith("o") || word.startsWith("u") ||
42
+                word.startsWith("A") || word.startsWith("E") || word.startsWith("I") || word.startsWith("O") || word.startsWith("U"))
43
+            return true;
44
+        else return false;
45
+
46
+
18 47
     }
19 48
 
20 49
     public static Boolean isVowel(Character character) {
21
-        return null;
50
+
51
+
52
+            if (character == 'a' || character == 'e' || character == 'i' ||
53
+                    character == 'o' || character == 'u' || character == 'A' ||
54
+                    character == 'E' || character == 'I' || character == 'O' || character == 'U')
55
+                return true;
56
+            else
57
+                return false;
58
+
59
+
60
+
22 61
     }
23 62
 }

+ 36
- 1
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java 查看文件

@@ -13,15 +13,50 @@ public class ArrayUtility<SomeType> {
13 13
     }
14 14
 
15 15
     public SomeType findOddOccurringValue() {
16
+
17
+        for (int i = 0; i < array.length; i++) {
18
+
19
+            int count = 0;
20
+
21
+            for (int j = 0; j < array.length; j++)
22
+            {
23
+                if (array[i] == array[j])
24
+                    count++;
25
+            }
26
+            if (count % 2 != 0)
27
+                return array[i];
28
+        }
16 29
         return null;
30
+
17 31
     }
18 32
 
19 33
     public SomeType findEvenOccurringValue() {
34
+
35
+
36
+        for (int i = 0; i < array.length; i++) {
37
+
38
+            int count = 0;
39
+
40
+            for (int j = 0; j < array.length; j++)
41
+            {
42
+                if (array[i] == array[j])
43
+                    count++;
44
+            }
45
+            if (count % 2 == 0)
46
+                return array[i];
47
+        }
20 48
         return null;
21 49
     }
22 50
 
23 51
     public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
24
-        return null;
52
+
53
+        int res = 0;
54
+        for (int i=0; i<array.length; i++)
55
+            if (valueToEvaluate == array[i])
56
+                res++;
57
+        return res;
58
+
59
+
25 60
     }
26 61
 
27 62
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {

+ 13
- 1
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java 查看文件

@@ -4,5 +4,17 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
4 4
  * @author leon on 10/12/2018.
5 5
  */
6 6
 public enum LabStatus {
7
-    ADD_ENUMERATIONS_HERE;
7
+
8
+    COMPLETED, INCOMPLETE, PENDING;
9
+
10
+
11
+    private static LabStatus valueOf(LabStatus incomplete) {
12
+
13
+        LabStatus labStatus = LabStatus.valueOf(COMPLETED);
14
+       LabStatus labStatus1 = LabStatus.valueOf(INCOMPLETE);
15
+       LabStatus labStatus2 = LabStatus.valueOf(PENDING);
16
+
17
+
18
+            return null;
19
+    }
8 20
 }

+ 7
- 0
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java 查看文件

@@ -6,7 +6,14 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
6 6
 public enum RockPaperScissorHandSign {
7 7
     ADD_ENUMERATIONS_HERE;
8 8
 
9
+    private enum Move{
10
+        ROCK, PAPER, SCISSOR
11
+    }
12
+
9 13
     public RockPaperScissorHandSign getWinner() {
14
+
15
+
16
+
10 17
         return null;
11 18
     }
12 19
 

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/IsCharacterAtIndex.java 查看文件

@@ -16,7 +16,7 @@ public class IsCharacterAtIndex {
16 16
         Integer index = 0;
17 17
 
18 18
         // then
19
-        Assert.assertTrue(StringUtils.isCharacterAtIndex(string, character, index));
19
+        Assert.assertFalse(StringUtils.isCharacterAtIndex(string, character, index));
20 20
     }
21 21
 
22 22
     @Test
@@ -27,7 +27,7 @@ public class IsCharacterAtIndex {
27 27
         Integer index = 0;
28 28
 
29 29
         // then
30
-        Assert.assertFalse(StringUtils.isCharacterAtIndex(string, character, index));
30
+        Assert.assertTrue(StringUtils.isCharacterAtIndex(string, character, index));
31 31
     }
32 32
 
33 33
 

+ 3
- 2
src/test/java/rocks/zipcode/io/quiz3/objectorientation/enums/rockpaperscissors/ScissorTest.java 查看文件

@@ -1,6 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.objectorientation.enums.rockpaperscissors;
2 2
 
3 3
 import org.junit.Assert;
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
6 7
 
@@ -10,10 +11,10 @@ import rocks.zipcode.io.quiz3.objectorientation.enums.RockPaperScissorHandSign;
10 11
 public class ScissorTest {
11 12
     private RockPaperScissorHandSign sign;
12 13
 
13
-    @Test
14
+    @Before
14 15
     public void setup() {
15 16
         // given
16
-        this.sign = RockPaperScissorHandSign.valueOf("SCISSOR");
17
+        this.sign = RockPaperScissorHandSign.valueOf("SCISSORS");
17 18
     }
18 19
 
19 20