Pārlūkot izejas kodu

completed piglatin

mpierse 6 gadus atpakaļ
vecāks
revīzija
fc1483117f

+ 17
- 3
src/main/java/rocks/zipcode/io/quiz3/collections/Lab.java Parādīt failu

@@ -1,27 +1,41 @@
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 9
 
8 10
     String name;
11
+    String labStatus;
12
+    Boolean forked=false;
13
+
14
+    public Boolean getForked() {
15
+        return forked;
16
+    }
17
+
18
+    public void setForked(Boolean forked) {
19
+        this.forked = forked;
20
+    }
9 21
 
10 22
     public Lab() {
11
-        this(null);
23
+        this("RandomLab");
12 24
     }
13 25
 
14 26
     public Lab(String labName) {
27
+        this.name=labName;
15 28
     }
16 29
 
17 30
     public String getLabStatus() {
18
-        return null;
31
+        return labStatus;
19 32
     }
20 33
 
21 34
     public void setLabStatus(String labStatus) {
35
+        this.labStatus=labStatus;
22 36
     }
23 37
 
24 38
     public String getName() {
25
-        return null;
39
+        return this.name;
26 40
     }
27 41
 }

+ 24
- 1
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java Parādīt failu

@@ -2,7 +2,9 @@ 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.
@@ -12,7 +14,7 @@ public class Student {
12 14
     Map<Lab, LabStatus> map;
13 15
 
14 16
     public Student() {
15
-        this(null);
17
+        this(new HashMap<>());
16 18
     }
17 19
 
18 20
     public Student(Map<Lab, LabStatus> map) {
@@ -20,13 +22,34 @@ public class Student {
20 22
     }
21 23
 
22 24
     public void setLabStatus(Lab lab, LabStatus labStatus) {
25
+
26
+        map.put(lab,labStatus);
27
+        if(!lab.getForked()){
28
+            throw new UnsupportedOperationException("Method not yet implemented"); }
23 29
     }
24 30
 
25 31
 
26 32
     public void forkLab(Lab lab) {
33
+       lab.setForked(true);
34
+       map.put(lab, LabStatus.PENDING);
27 35
     }
28 36
 
29 37
     public LabStatus getLabStatus(String labName) {
38
+        //throw new UnsupportedOperationException("Method not yet implemented");
39
+        for (Lab l: map.keySet()) {
40
+            if( l.getName().equals(labName)) {
41
+                return map.get(l);
42
+            }
43
+        }
30 44
         throw new UnsupportedOperationException("Method not yet implemented");
31 45
     }
46
+
47
+    @Override
48
+    public String toString(){
49
+        String result = "";
50
+        for (Lab l: map.keySet()) {
51
+            result = l.getName() + " > " + getLabStatus(l.getName()) + "\n" + result;
52
+        }
53
+        return result.substring(0, result.length()-1);
54
+    }
32 55
 }

+ 34
- 1
src/main/java/rocks/zipcode/io/quiz3/fundamentals/PigLatinGenerator.java Parādīt failu

@@ -4,7 +4,40 @@ package rocks.zipcode.io.quiz3.fundamentals;
4 4
  * @author leon on 09/12/2018.
5 5
  */
6 6
 public class PigLatinGenerator {
7
+
7 8
     public String translate(String str) {
8
-        return null;
9
+        String[] strToParse = str.split(" ");
10
+        String result = "";
11
+        for (String s: strToParse) {
12
+            if (startsWithVowel(s))
13
+                {result += startsVowel(s) + " ";}
14
+            else {result += startsConsinent(s) + " ";}
15
+        }
16
+        return result.substring(0, result.length()-1);
17
+    }
18
+
19
+    public String startsVowel(String str){
20
+        return str + "way";
21
+    }
22
+
23
+    public String startsConsinent(String str){
24
+        int index = -1;
25
+        for (int i = 0; i < str.length() ; i++) {
26
+            if (str.charAt(i) == 'a'  || str.charAt(i) == 'e' || str.charAt(i) == 'i'
27
+            || str.charAt(i) =='o' || str.charAt(i) == 'u' || str.charAt(i) == 'A' ||
28
+                    str.charAt(i) == 'E' || str.charAt(i) == 'I' || str.charAt(i) == 'O'
29
+            || str.charAt(i) == 'U')
30
+            {  index = i;
31
+            break;}
32
+        }
33
+        if(index == -1) return str+"ay";
34
+        return str.substring(index) + str.substring(0,index) + "ay";
35
+    }
36
+
37
+    public boolean startsWithVowel(String str){
38
+        return  (str.startsWith("a")||str.startsWith("e")||str.startsWith("i")||
39
+                str.startsWith("o")||str.startsWith("u")||str.startsWith("A")||
40
+                str.startsWith("E")||str.startsWith("I")||str.startsWith("O")||str.startsWith("U"));
9 41
     }
42
+
10 43
 }

+ 17
- 3
src/main/java/rocks/zipcode/io/quiz3/objectorientation/enums/LabStatus.java Parādīt failu

@@ -4,7 +4,21 @@ package rocks.zipcode.io.quiz3.objectorientation.enums;
4 4
  * @author leon on 10/12/2018.
5 5
  */
6 6
 public enum LabStatus {
7
-    PENDING,
8
-    COMPLETED,
9
-    INCOMPLETE;
7
+    PENDING("PENDING"),
8
+    COMPLETED("COMPLETED"),
9
+    INCOMPLETE("INCOMPLETE");
10
+
11
+    String name;
12
+
13
+    LabStatus(String name) {
14
+        this.name=name;
15
+    }
16
+
17
+    public String getName() {
18
+        return name;
19
+    }
20
+
21
+    public void setName(String name) {
22
+        this.name = name;
23
+    }
10 24
 }