Nuridalia.Hernandez 5 年之前
父節點
當前提交
c46d6ba32a

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

@@ -7,42 +7,117 @@ public class TicTacToe {
7 7
     String [][] board;
8 8
 
9 9
     public TicTacToe(String[][] board) {
10
+        this.board= board;
10 11
 
11 12
 
12 13
     }
13 14
 
14 15
     public String[] getRow(Integer value) {
16
+        String[] result = new String[3];
15 17
 
16
-
18
+        int index = 0;
17 19
 
18 20
         for (int i = 0; i < board.length; i++) {
19
-            for (int j = 0; j < board.length; j++) {
20
-                 if (i == value) {
21
-
22
-                 }
23
-
21
+            for (int j = 0; j < board[i].length; j++) {
22
+                if (board[value] == board[i]) {
23
+                    result[index] = board[value][j];
24
+                        index++;
25
+                }
24 26
 
25 27
             }
26
-
27 28
         }
28 29
 
29
-        return null;
30
+            return result;
31
+
30 32
     }
31 33
 
34
+
32 35
     public String[] getColumn(Integer value) {
33
-        return null;
36
+        String[] result = new String[3];
37
+        int index = 0;
38
+
39
+        for (int i = 0; i < board.length; i++) {
40
+            for (int j = 0; j < board[i].length-1; j++) {
41
+                if (board[i][value] == board[i][j]) {
42
+                    result[index] = board[i][value];
43
+                    index++;
44
+                }
45
+
46
+            }
47
+        }
48
+
49
+        return result;
50
+
34 51
     }
35 52
 
36 53
     public Boolean isRowHomogenous(Integer rowIndex) {
37
-        return null;
54
+        Boolean result = false;
55
+
56
+ String [] row = new String[getRow(rowIndex).length];
57
+        for (int i = 1; i < row.length; i++) {
58
+                if (row[0] == row[i]) {
59
+                    result = true;
60
+
61
+                } else {
62
+                    result = false;
63
+                }
64
+
65
+            }
66
+
67
+
68
+        return result;
38 69
     }
39 70
 
40 71
     public Boolean isColumnHomogeneous(Integer columnIndex) {
41
-        return null;
72
+        Boolean result = false;
73
+        String [] collum = new String[getColumn(columnIndex).length];
74
+        for (int i = 1; i < collum.length-1; i++) {
75
+            if (collum[0] == collum[i]) {
76
+                result = true;
77
+
78
+            } else {
79
+                result = false;
80
+            }
81
+
82
+        }
83
+
84
+
85
+        return result;
86
+
42 87
     }
43 88
 
44 89
     public String getWinner() {
45 90
 
46
-        return null;
91
+
92
+        String str = "X";
93
+
94
+        if (board[1][1] == "X"){
95
+            if (board[0][0] == "X"){
96
+                if (board[2][2] == "X"){
97
+               str= "X";
98
+                }
99
+            }
100
+            else if (board[0][1] == "X"){
101
+                if (board[2][1] == "X"){
102
+                    str="X";
103
+                }
104
+            }
105
+            else if (board[1][0] == "X"){
106
+                if (board[1][2] == "X"){
107
+                    System.out.println("X wins");
108
+                }
109
+            }
110
+            else if (board[2][0] == "X"){
111
+                if (board[0][2] == "X"){
112
+                    str = "X";
113
+                }
114
+
115
+
116
+            }
117
+
118
+            }
119
+
120
+
121
+        return str;
47 122
     }
48 123
 }

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

@@ -10,6 +10,8 @@ public class WaveGenerator {
10 10
 
11 11
 
12 12
 
13
+
13 14
         return null;
14 15
     }
16
+
15 17
 }

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

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

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

@@ -2,27 +2,40 @@ package rocks.zipcode.io.quiz3.collections;
2 2
 
3 3
 import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
4 4
 
5
+import java.util.HashMap;
5 6
 import java.util.Map;
7
+import java.util.TreeMap;
6 8
 
7 9
 /**
8 10
  * @author leon on 10/12/2018.
9 11
  */
10 12
 public class Student {
13
+
14
+
15
+    Map <Lab, LabStatus>  map = new HashMap<>();
16
+
11 17
     public Student() {
12 18
         this(null);
13 19
     }
14 20
 
15 21
     public Student(Map<Lab, LabStatus> map) {
22
+        this.map=map;
23
+
16 24
     }
17 25
 
18 26
     public void setLabStatus(Lab lab, LabStatus labStatus) {
27
+
28
+
19 29
     }
20 30
 
21 31
 
22 32
     public void forkLab(Lab lab) {
33
+
23 34
     }
24 35
 
25 36
     public LabStatus getLabStatus(String labName) {
26 37
         throw new UnsupportedOperationException("Method not yet implemented");
38
+
39
+
27 40
     }
28 41
 }

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

@@ -1,10 +1,24 @@
1 1
 package rocks.zipcode.io.quiz3.fundamentals;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 09/12/2018.
5 7
  */
6 8
 public class PigLatinGenerator {
7 9
     public String translate(String str) {
8
-        return null;
10
+
11
+
12
+        int len = str.length();
13
+        int index = -1;
14
+        for (int i = 0; i < len; i++) {
15
+            if (VowelUtils.isVowel(str.charAt(i))) {
16
+                index = i;
17
+                break;
18
+            }
19
+        }
20
+        return str.substring(index) +
21
+                str.substring(0, index) + "ay";
22
+
9 23
     }
10 24
 }

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

@@ -4,5 +4,6 @@ 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
+    COMPLETED ,INCOMPLETE,PENDING
8
+
8 9
 }

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

@@ -4,9 +4,12 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public enum RockPaperScissorHandSign {
7
-    ADD_ENUMERATIONS_HERE;
7
+    ROCK, PAPER , SCISSOR;
8 8
 
9 9
     public RockPaperScissorHandSign getWinner() {
10
+        if si
11
+
12
+
10 13
         return null;
11 14
     }
12 15
 

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz3/arrays/tictactoe/IsRowHomogeneousTest.java 查看文件

@@ -24,7 +24,7 @@ public class IsRowHomogeneousTest {
24 24
     @Test
25 25
     public void test2() {
26 26
         // given
27
-        String[] row1 = {"X", "X", "X"};
27
+        String[] row1 = {"X", "O", "X"};
28 28
         String[] row2 = {"O", "O", "O"};
29 29
         String[] row3 = {"O", "X", "O"};
30 30
         String[][] board = {row1, row2, row3};