Christian Sheridan 6 years ago
parent
commit
f85f784f18

+ 2
- 1
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java View File

@@ -7,12 +7,13 @@ import java.util.TreeSet;
7 7
  */
8 8
 public class ComparableTreeSet<_> {
9 9
     public ComparableTreeSet(_... arr) {
10
-    }
11 10
 
11
+    }
12 12
 
13 13
     public ComparableTreeSet() {
14 14
     }
15 15
 
16 16
     public Integer compareTo(ComparableTreeSet<_> o) {
17
+        return null;
17 18
     }
18 19
 }

+ 20
- 6
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java View File

@@ -1,36 +1,50 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import com.sun.tools.javac.util.List;
4
+
5
+import java.util.*;
6
+import java.util.function.Consumer;
7
+
3 8
 /**
4 9
  * @author leon on 11/12/2018.
5 10
  */
6
-public class SimpleStringGroup {
11
+public class SimpleStringGroup implements Iterable{
12
+
13
+    ArrayList<String> simpleString = new ArrayList<>();
7 14
 
8
-    String simpleString;
9 15
 
10 16
     public SimpleStringGroup() {
11
-        throw new UnsupportedOperationException("Method not yet implemented");
12 17
     }
13 18
 
14 19
     public Integer count() {
15
-        return simpleString.length();
20
+        return simpleString.size();
16 21
     }
17 22
 
18 23
     public void insert(String string) {
19
-        simpleString = string;
24
+        simpleString.add(string);
20 25
     }
21 26
 
22 27
     public Boolean has(String valueToInsert) {
28
+        return this.contains(valueToInsert);
29
+    }
30
+
31
+    private Boolean contains(String valueToInsert) {
23 32
         return simpleString.contains(valueToInsert);
24 33
     }
25 34
 
26 35
     public String fetch(int indexOfValue) {
27
-        return null;
36
+       return simpleString.get(indexOfValue);
28 37
     }
29 38
 
30 39
     public void delete(String valueToInsert) {
40
+        simpleString.remove(valueToInsert);
31 41
     }
32 42
 
33 43
     public void clear() {
44
+        simpleString.removeAll(simpleString);
45
+    }
34 46
 
47
+    public Iterator<String> iterator() {
48
+        return simpleString.iterator();
35 49
     }
36 50
 }

+ 16
- 2
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java View File

@@ -2,23 +2,37 @@ package rocks.zipcode.io.quiz4.collections;
2 2
 
3 3
 import rocks.zipcode.io.quiz4.objectorientation.Student;
4 4
 
5
+import java.util.ArrayList;
6
+import java.util.HashMap;
5 7
 import java.util.Map;
8
+import java.util.TreeMap;
6 9
 
7 10
 /**
8 11
  * @author leon on 11/12/2018.
9 12
  */
10 13
 public class ZipCodeWilmington {
14
+
15
+    ArrayList<Student> zipCodeWilmington = new ArrayList<Student>();
16
+
11 17
     public void enroll(Student student) {
18
+        zipCodeWilmington.add(student);
12 19
     }
13 20
 
14 21
     public Boolean isEnrolled(Student student) {
15
-        return null;
22
+        return zipCodeWilmington.contains(student);
16 23
     }
17 24
 
18 25
     public void lecture(double numberOfHours) {
26
+        for(Student s: zipCodeWilmington){
27
+            s.learn(numberOfHours);
28
+        }
19 29
     }
20 30
 
21 31
     public Map<Student, Double> getStudyMap() {
22
-        return null;
32
+        HashMap<Student, Double> studyMap = new HashMap<>();
33
+        for(Student s: zipCodeWilmington){
34
+            studyMap.put(s, s.getTotalStudyTime());
35
+        }
36
+        return studyMap;
23 37
     }
24 38
 }

+ 1
- 0
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java View File

@@ -16,3 +16,4 @@ public class GenericUtils {
16 16
         return powerSet(new TreeSet<>(Arrays.asList(originalSet)));
17 17
     }
18 18
 }
19
+

+ 22
- 6
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java View File

@@ -1,37 +1,53 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.Iterator;
4 5
 
5 6
 /**
6 7
  * @author leon on 18/12/2018.
7 8
  */
8
-public class Group<_> {
9
+public class Group<_> implements Iterable{
10
+
11
+    ArrayList<_> group = new ArrayList<_>();
12
+
13
+    public Group(ArrayList<_> group) {
14
+        this.group = group;
15
+    }
16
+
9 17
     public Group() {
10
-        throw new UnsupportedOperationException("Method not yet implemented");
11 18
     }
12 19
 
13 20
     public Integer count() {
14
-        return null;
21
+        return group.size();
15 22
     }
16 23
 
17 24
     public void insert(_ value) {
25
+        group.add(value);
18 26
     }
19 27
 
20 28
     public Boolean has(_ value) {
21
-        return null;
29
+        return group.contains(value);
22 30
     }
23 31
 
24 32
     public _ fetch(int indexOfValue) {
25
-        return null;
33
+        return group.get(indexOfValue);
26 34
     }
27 35
 
28 36
     public void delete(_ value) {
37
+        group.remove(value);
29 38
     }
30 39
 
31 40
     public void clear() {
41
+        group.removeAll(group);
32 42
     }
33 43
 
34 44
     public Iterator<_> iterator() {
35
-        return null;
45
+        return group.iterator();
36 46
     }
47
+
48
+    @Override
49
+    public String toString(){
50
+        return group.toString();
51
+    }
52
+
37 53
 }

+ 4
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java View File

@@ -4,7 +4,11 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 18/12/2018.
5 5
  */
6 6
 public class PalindromeObject {
7
+
8
+    String input;
9
+
7 10
     public PalindromeObject(String input) {
11
+        this.input = input;
8 12
     }
9 13
 
10 14
     public String[] getAllPalindromes(){

+ 6
- 1
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java View File

@@ -4,11 +4,16 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 11/12/2018.
5 5
  */
6 6
 public class StringAssembler {
7
+
8
+    String stringAssembler;
9
+    Character delimeter;
10
+
7 11
     public StringAssembler(Character delimeter) {
12
+        this.delimeter = delimeter;
8 13
     }
9 14
 
10 15
     public StringAssembler append(String str) {
11
-        return null;
16
+
12 17
     }
13 18
 
14 19
     public String assemble() {

+ 4
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java View File

@@ -4,7 +4,11 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 19/12/2018.
5 5
  */
6 6
 public class StringEvaluatorObject {
7
+
8
+    String str;
9
+
7 10
     public StringEvaluatorObject(String str) {
11
+        this.str = str;
8 12
     }
9 13
 
10 14
     public String[] getAllPrefixes() {

+ 19
- 3
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java View File

@@ -4,17 +4,33 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 11/12/2018.
5 5
  */
6 6
 public class Student {
7
-    public Student() {
8
-        this(null);
7
+
8
+    public Student(Integer id, Double amountOfHours) {
9
+        this.id = id;
10
+        this.amountOfHours = amountOfHours;
11
+    }
12
+
13
+    Integer id = 0;
14
+    Double amountOfHours = 0.0;
15
+
16
+
17
+
18
+    public Student(double amountOfHours) {
19
+        this.amountOfHours = amountOfHours;
20
+    }
21
+
22
+    public Student(){
9 23
     }
10 24
 
11 25
     public Student(Integer id) {
26
+        this.id = id;
12 27
     }
13 28
 
14 29
     public void learn(Double amountOfHours) {
30
+        this.amountOfHours += amountOfHours;
15 31
     }
16 32
 
17 33
     public Double getTotalStudyTime() {
18
-        return null;
34
+        return amountOfHours;
19 35
     }
20 36
 }