#31 Second Commit

Open
NiraParikh wants to merge 3 commits from NiraParikh/Quiz3:master into master

+ 6
- 0
pom.xml View File

@@ -26,6 +26,12 @@
26 26
             <version>4.12</version>
27 27
             <scope>test</scope>
28 28
         </dependency>
29
+        <dependency>
30
+            <groupId>junit</groupId>
31
+            <artifactId>junit</artifactId>
32
+            <version>4.12</version>
33
+            <scope>test</scope>
34
+        </dependency>
29 35
     </dependencies>
30 36
 
31 37
 

+ 12
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/SquareArrayAnalyzer.java View File

@@ -4,7 +4,18 @@ package rocks.zipcode.io.quiz3.arrays;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public class SquareArrayAnalyzer {
7
+    private static Integer[] input;
8
+    private static Integer[] squaredValues;
9
+
10
+    public SquareArrayAnalyzer() {
11
+    }
12
+
7 13
     public static Boolean compare(Integer[] input, Integer[] squaredValues) {
8
-        return null;
14
+
15
+
16
+        if (input.equals(squaredValues)){
17
+            return false;
18
+        }
19
+return true;
9 20
     }
10 21
 }

+ 40
- 6
src/main/java/rocks/zipcode/io/quiz3/arrays/TicTacToe.java View File

@@ -1,30 +1,64 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+import com.sun.rowset.internal.Row;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class TicTacToe {
7 9
 
10
+    private final int Row = 3;
11
+    private final int Column = 3;
12
+
13
+//    Board[][] board = new Board[][];
14
+
15
+    TicTacToe ticTacToe = new TicTacToe();
16
+
8 17
     public TicTacToe(String[][] board) {
18
+//        board = new String[][][Row][Column];
9 19
     }
10 20
 
21
+    public TicTacToe() {}
22
+
11 23
     public String[] getRow(Integer value) {
24
+        for (int row = value; row < 3; row++) {
25
+
26
+            return ticTacToe.getRow(value);
27
+
28
+        }
12 29
         return null;
13 30
     }
14 31
 
15 32
     public String[] getColumn(Integer value) {
16 33
         return null;
17
-    }
34
+            }
35
+
18 36
 
19 37
     public Boolean isRowHomogenous(Integer rowIndex) {
20
-        return null;
38
+        return true;
21 39
     }
22 40
 
23 41
     public Boolean isColumnHomogeneous(Integer columnIndex) {
24
-        return null;
42
+        return false;
25 43
     }
26 44
 
27 45
     public String getWinner() {
28
-        return null;
29
-    }
30
-}
46
+//        for (int r = 0; r < 3; r++) {
47
+//            if (board[r][0] == board[r][1] && board[r][1] == board[r][2] && board[r][0] != '-')
48
+//                return true;
49
+//        }
50
+//        //loops through columns checking if win-condition exists
51
+//        for (int c = 0; c < 3; c++) {
52
+//            if (board[0][c] == board[1][c] && board[1][c] == board[2][c] && board[0][c] != '-' )
53
+//                return true;
54
+//        }
55
+//        //checks diagonals for win-condition
56
+//        if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != '-')
57
+//            return true;
58
+//
59
+//        if (board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][0] != '-')
60
+//            return true;
61
+//
62
+        return "Won";
63
+
64
+}}

+ 17
- 1
src/main/java/rocks/zipcode/io/quiz3/arrays/WaveGenerator.java View File

@@ -1,10 +1,26 @@
1 1
 package rocks.zipcode.io.quiz3.arrays;
2 2
 
3
+
4
+import java.util.Arrays;
5
+import java.util.List;
6
+import java.util.stream.*;
7
+
3 8
 /**
4 9
  * @author leon on 09/12/2018.
5 10
  */
6 11
 public class WaveGenerator {
7 12
     public static String[] wave(String str) {
8
-        return null;
13
+
14
+        String words[]=str.split(" ");
15
+        String capitalizeWord=" ";
16
+        for(String w:words){
17
+            String first = w.substring(0,1);
18
+            String afterfirst = w.substring(1);
19
+            capitalizeWord +=first.toUpperCase()+afterfirst+" ";
20
+
21
+        }
22
+        return new String[]{capitalizeWord};
23
+
9 24
     }
10 25
 }
26
+

+ 23
- 3
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java View File

@@ -4,21 +4,41 @@ package rocks.zipcode.io.quiz3.collections;
4 4
  * @author leon on 10/12/2018.
5 5
  */
6 6
 public class Lab {
7
+    private String lab;
8
+    private String name;
9
+    private String labStatus;
10
+
11
+
12
+    public Lab(String lab, String name, String labStatus) {
13
+        this.lab = lab;
14
+        this.name = name;
15
+        this.labStatus = labStatus;
16
+    }
17
+
18
+    public Lab(String lab, String name) {
19
+        this.lab = lab;
20
+        this.name = name;
21
+    }
22
+
7 23
     public Lab() {
8
-        this(null);
24
+        this.lab = "duplicate deleter";
25
+
9 26
     }
10 27
 
11 28
     public Lab(String labName) {
29
+        this.lab = labName;
12 30
     }
13 31
 
14 32
     public String getLabStatus() {
15
-        return null;
33
+
34
+        return labStatus;
16 35
     }
17 36
 
18 37
     public void setLabStatus(String labStatus) {
38
+        this.lab = "PENDING";
19 39
     }
20 40
 
21 41
     public String getName() {
22
-        return null;
42
+        return name;
23 43
     }
24 44
 }

+ 24
- 1
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java View File

@@ -7,19 +7,42 @@ import java.util.Map;
7 7
 /**
8 8
  * @author leon on 10/12/2018.
9 9
  */
10
-public class Student {
10
+public class Student extends Lab {
11
+
12
+    private Lab lab;
13
+    private LabStatus labStatus;
14
+    private LabStatus labName;
15
+
16
+
17
+
18
+    public Student(Lab lab, LabStatus labStatus, LabStatus labName) {
19
+        this.lab = lab;
20
+        this.labStatus = labStatus;
21
+        this.labName = labName;
22
+    }
23
+
24
+    @Override
25
+    public boolean equals(Object obj) {
26
+        return super.equals(obj);
27
+    }
28
+
11 29
     public Student() {
12 30
         this(null);
13 31
     }
14 32
 
15 33
     public Student(Map<Lab, LabStatus> map) {
34
+       Lab lab = new Lab();
35
+
16 36
     }
17 37
 
18 38
     public void setLabStatus(Lab lab, LabStatus labStatus) {
39
+            this.lab = lab;
40
+            this.labStatus = labStatus;
19 41
     }
20 42
 
21 43
 
22 44
     public void forkLab(Lab lab) {
45
+        this.lab = lab;
23 46
     }
24 47
 
25 48
     public LabStatus getLabStatus(String labName) {

+ 38
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java View File

@@ -1,10 +1,45 @@
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 {
7 11
     public String translate(String str) {
8
-        return null;
9
-    }
10
-}
12
+        char Constant;
13
+
14
+        char[] vowels = {'a', 'e', 'i', 'o', 'u'};
15
+        char first = str.charAt(0);
16
+
17
+        if (first == -1)
18
+            return "-1";
19
+        for (int i = 0; i < vowels.length; i++) {
20
+
21
+            if (first == vowels[i]) {
22
+                return str + "way";
23
+            }
24
+        }
25
+        str = str.substring(1);
26
+        str += first + "ay";
27
+
28
+int len = str.length();
29
+int index = -1;
30
+        for (int i = 0; i < len ; i++) {
31
+            if(isVowel(str.charAt(i))){
32
+                index = i;
33
+                break;
34
+            }
35
+        }
36
+        if(index ==-1){
37
+            return str + "ay";
38
+        }
39
+    return str;
40
+}}
41
+
42
+
43
+
44
+
45
+

+ 11
- 3
src/main/java/rocks/zipcode/io/quiz3/fundamentals/StringUtils.java View File

@@ -5,10 +5,18 @@ 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
+        String cap = str.substring(0, 1).toUpperCase() + str.substring(1);
10
+        return cap;
11
+    }
12
+
13
+public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
14
+
15
+     Character c = baseString.charAt(indexOfString);
16
+    if(characterToCheckFor.equals(c)){
17
+        return true;
9 18
     }
19
+    return false;
10 20
 
11
-    public static Boolean isCharacterAtIndex(String baseString, Character characterToCheckFor, Integer indexOfString) {
12
-        return null;
13 21
     }
14 22
 }

+ 23
- 5
src/main/java/rocks/zipcode/io/quiz3/fundamentals/VowelUtils.java View File

@@ -1,23 +1,41 @@
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
+        for (int i = 0; i < word.length(); i++) {
11
+            char c = word.charAt(i);
12
+            if (isVowel(c)) {
13
+                return true;
14
+            }
15
+        }
16
+        return false;
9 17
     }
10 18
 
11 19
     public static Integer getIndexOfFirstVowel(String word) {
20
+        for (int i = 0; i < word.length(); ++i) {
21
+            if (isVowel(word.charAt(i))){
22
+                return i;
23
+            }
24
+        }
12 25
         return null;
13 26
     }
14 27
 
15
-
16
-    public static Boolean startsWithVowel(String word) {
17
-        return null;
28
+     public static Boolean startsWithVowel(String word) {
29
+         if ((word.charAt(0) =='a')||(word.charAt(0)=='e')||(word.charAt(0)=='i')||(word.charAt(0)=='o')||(word.charAt(0)=='u')) {
30
+             return true;
31
+         }else if ((word.charAt(0) =='A')||(word.charAt(0)=='E')||(word.charAt(0)=='I')||(word.charAt(0)=='O')||(word.charAt(0)=='U')){
32
+             return true;
33
+     }
34
+    return false;
18 35
     }
19 36
 
20 37
     public static Boolean isVowel(Character character) {
21
-        return null;
38
+
39
+        return "aeiouAEIOU".indexOf(character) >= 0;
22 40
     }
23 41
 }

+ 34
- 3
src/main/java/rocks/zipcode/io/quiz3/generics/ArrayUtility.java View File

@@ -1,6 +1,7 @@
1 1
 package rocks.zipcode.io.quiz3.generics;
2 2
 
3 3
 import java.util.function.Function;
4
+import java.util.stream.Stream;
4 5
 
5 6
 /**
6 7
  * @author leon on 09/12/2018.
@@ -13,18 +14,48 @@ public class ArrayUtility<SomeType> {
13 14
     }
14 15
 
15 16
     public SomeType findOddOccurringValue() {
17
+
18
+        int i;
19
+        for (i = 0; i < array.length; i++) {
20
+            int count = 0;
21
+            for (int j = 0; j < array.length; j++) {
22
+                if (array[i] == array[j])
23
+                    count++;
24
+            }
25
+            if (count % 2 != 0)
26
+                return array[i];
27
+        }
16 28
         return null;
17 29
     }
18 30
 
19 31
     public SomeType findEvenOccurringValue() {
32
+        int i;
33
+        for (i = 0; i < array.length; i++) {
34
+            int count = 0;
35
+            for (int j = 0; j < array.length; j++) {
36
+                if (array[i] == array[j])
37
+                    count++;
38
+            }
39
+            if (count % 2 == 0)
40
+                return array[i];
41
+        }
20 42
         return null;
21 43
     }
22 44
 
23
-    public Integer getNumberOfOccurrences(SomeType valueToEvaluate) {
24
-        return null;
45
+    public Integer getNumberOfOccurrences(SomeType valueToEvaluate)
46
+    {
47
+        Integer count =0;
48
+
49
+        for (int i = 0; i < array.length ; i++) {
50
+            if(array[i].equals(valueToEvaluate)){
51
+                count++;
52
+            }
53
+        }
54
+        return count;
25 55
     }
26 56
 
57
+
27 58
     public SomeType[] filter(Function<SomeType, Boolean> predicate) {
28
-        return null;
59
+            return null;
29 60
     }
30 61
 }

+ 6
- 2
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java View File

@@ -4,5 +4,9 @@ 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;
8
-}
7
+        INCOMPLETE,
8
+        PENDING,
9
+        COMPLETED;
10
+   }
11
+
12
+

+ 33
- 4
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/RockPaperScissorHandSign.java View File

@@ -1,16 +1,45 @@
1 1
 package rocks.zipcode.io.quiz3.objectorientation.enums;
2 2
 
3
+import java.util.Arrays;
4
+import java.util.Collections;
5
+import java.util.HashSet;
6
+import java.util.List;
7
+
3 8
 /**
4 9
  * @author leon on 09/12/2018.
5 10
  */
6 11
 public enum RockPaperScissorHandSign {
7
-    ADD_ENUMERATIONS_HERE;
8 12
 
9
-    public RockPaperScissorHandSign getWinner() {
10
-        return null;
13
+     ROCK, PAPER, SCISSORS;
14
+
15
+//    protected static final String ROCK ;
16
+//    protected static final String PAPER;
17
+//    protected static final String SCISSORS = "scissors";
18
+
19
+
20
+//    public RockScissorPaper() {
21
+//        this.winSituations = new HashSet<>();
22
+//
23
+//        this.winSituations.add(new Situation("Rock", "Scissor"));
24
+//        this.winSituations.add(new Situation("Scissor", "Paper"));
25
+//        this.winSituations.add(new Situation("Paper", "Rock"));
26
+//    }
27
+
28
+        public RockPaperScissorHandSign getWinner() {
29
+//            if (this.winSituations.contains(situation)) {
30
+//                return Result.PLAYER1_WINS;
31
+//            } else if (this.winSituations.contains(situation.invert())) {
32
+//                return Result.PLAYER2_WINS;
33
+//            } else {
34
+//                return Result.TIE;
35
+//            }
36
+//
37
+//        }
38
+            return null;
11 39
     }
12 40
 
41
+
13 42
     public RockPaperScissorHandSign getLoser() {
14
-        return null;
43
+        return ROCK;
15 44
     }
16 45
 }

+ 2
- 2
src/test/java/rocks/zipcode/io/quiz3/fundamentals/stringutils/IsCharacterAtIndex.java View File

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