Demetrius Murray 6 years ago
parent
commit
42bf6c416b

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

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

+ 30
- 2
src/main/java/rocks/zipcode/io/quiz3/collections/Student.java View File

@@ -2,27 +2,55 @@ 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
+    Map<Lab, LabStatus> map;
15
+
11 16
     public Student() {
12
-        this(null);
17
+        this(new TreeMap<>());
13 18
     }
14 19
 
15 20
     public Student(Map<Lab, LabStatus> map) {
21
+        this.map = map;
16 22
     }
17 23
 
18 24
     public void setLabStatus(Lab lab, LabStatus labStatus) {
25
+        if (map.containsKey(lab) && map.get(lab).equals(LabStatus.PENDING)) {
26
+            lab.setLabStatus(labStatus.getLabStatusName());
27
+            map.put(lab, labStatus);
28
+        }
29
+        else throw new UnsupportedOperationException();
19 30
     }
20 31
 
21 32
 
22 33
     public void forkLab(Lab lab) {
34
+        map.put(lab,LabStatus.PENDING);
23 35
     }
24 36
 
25 37
     public LabStatus getLabStatus(String labName) {
26
-        throw new UnsupportedOperationException("Method not yet implemented");
38
+        try {
39
+            for (Lab l : map.keySet())
40
+                if (l.getName().equals(labName))
41
+                    return map.get(l);
42
+        } catch (Exception e) {
43
+            throw new UnsupportedOperationException();
44
+        }
45
+
46
+        return null;
47
+    }
48
+
49
+    @Override
50
+    public String toString() {
51
+        StringBuilder sb = new StringBuilder();
52
+        for (Lab l : map.keySet())
53
+            sb.append(l.getName()).append(" > ").append(l.getLabStatus()).append("\n");
54
+        return sb.toString().trim();
27 55
     }
28 56
 }

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

@@ -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
+    COMPLETED("COMPLETED"),
8
+    INCOMPLETE("INCOMPLETE"),
9
+    PENDING("PENDING");
10
+
11
+    private String labStatusName;
12
+
13
+    LabStatus(String labStatusName) {
14
+        this.labStatusName = labStatusName;
15
+    }
16
+
17
+    public String getLabStatusName() {
18
+        return labStatusName;
19
+    }
8 20
 }