Brandon Defrancis 6 年之前
父節點
當前提交
c42accd41b

+ 21
- 3
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java 查看文件

@@ -1,9 +1,15 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import java.util.Arrays;
4
+import java.util.TreeSet;
5
+
3 6
 /**
4 7
  * @author leon on 11/12/2018.
5 8
  */
6
-public class ComparableTreeSet<_> {
9
+public class ComparableTreeSet<_> extends TreeSet<_> implements Comparable<_> {
10
+
11
+    private TreeSet<_> treeSet = new TreeSet<>();
12
+
7 13
     public ComparableTreeSet(_... arr) {
8 14
     }
9 15
 
@@ -11,7 +17,19 @@ public class ComparableTreeSet<_> {
11 17
     public ComparableTreeSet() {
12 18
     }
13 19
 
14
-    public Integer compareTo(ComparableTreeSet<_> o) {
15
-        return null;
20
+
21
+    public int compareTo(ComparableTreeSet<_> o) {
22
+
23
+        return 0;
24
+    }
25
+
26
+    @Override
27
+    public int compareTo(_ o) {
28
+        return 0;
29
+    }
30
+
31
+    @Override
32
+    public String toString() {
33
+        return treeSet.toString();
16 34
     }
17 35
 }

+ 7
- 1
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java 查看文件

@@ -1,12 +1,13 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3 3
 import java.util.ArrayList;
4
+import java.util.Iterator;
4 5
 import java.util.List;
5 6
 
6 7
 /**
7 8
  * @author leon on 11/12/2018.
8 9
  */
9
-public class SimpleStringGroup {
10
+public class SimpleStringGroup implements Iterable {
10 11
 
11 12
     private List<String> group = new ArrayList<>();
12 13
     private Iterable<String> test = group;
@@ -47,4 +48,9 @@ public class SimpleStringGroup {
47 48
     public void clear() {
48 49
         group.clear();
49 50
     }
51
+
52
+    @Override
53
+    public Iterator iterator() {
54
+        return group.iterator();
55
+    }
50 56
 }

+ 17
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java 查看文件

@@ -2,24 +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;
7
+import java.util.List;
5 8
 import java.util.Map;
6 9
 
7 10
 /**
8 11
  * @author leon on 11/12/2018.
9 12
  */
10
-public class ZipCodeWilmington {
11
-    public void enroll(Student student) {
13
+public class ZipCodeWilmington extends Student {
14
+
15
+    private List<Student> cohort = new ArrayList<>();
16
+    private Map<Student, Double> cohort2 = new HashMap<>();
12 17
 
18
+    public void enroll(Student student) {
19
+        cohort.add(student);
13 20
     }
14 21
 
15 22
     public Boolean isEnrolled(Student student) {
16
-        return null;
23
+        return cohort.contains(student);
17 24
     }
18 25
 
19 26
     public void lecture(double numberOfHours) {
27
+        for(Student student : cohort){
28
+            student.learn(numberOfHours);
29
+        }
20 30
     }
21 31
 
22 32
     public Map<Student, Double> getStudyMap() {
23
-        return null;
33
+        for (Student student : cohort){
34
+            cohort2.put(student, student.getTotalStudyTime());
35
+        }
36
+        return cohort2;
24 37
     }
25 38
 }

+ 2
- 3
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java 查看文件

@@ -1,14 +1,13 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
-import java.util.Arrays;
4
-import java.util.Set;
5
-import java.util.TreeSet;
3
+import java.util.*;
6 4
 
7 5
 /**
8 6
  * @author leon on 11/12/2018.
9 7
  */
10 8
 public class GenericUtils {
11 9
     public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
10
+
12 11
         return null;
13 12
     }
14 13
 

+ 7
- 7
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java 查看文件

@@ -1,23 +1,18 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3 3
 import java.util.ArrayList;
4
+import java.util.Arrays;
4 5
 import java.util.Iterator;
5 6
 import java.util.List;
6 7
 
7 8
 /**
8 9
  * @author leon on 18/12/2018.
9 10
  */
10
-public class Group<_>{
11
+public class Group<_> implements Iterable<_>, GroupInterface<_>{
11 12
 
12 13
     List<_> group = new ArrayList<>();
13
-    Iterable<_> list = group;
14 14
 
15 15
     public Group() {
16
-        try {
17
-            throw new UnsupportedOperationException("Method not yet implemented");
18
-        }catch (UnsupportedOperationException uoe){
19
-            uoe.printStackTrace();
20
-        }
21 16
     }
22 17
 
23 18
     public Integer count() {
@@ -48,4 +43,9 @@ public class Group<_>{
48 43
         Iterator<_> list = group.iterator();
49 44
         return list;
50 45
     }
46
+
47
+    @Override
48
+    public String toString() {
49
+        return Arrays.toString(group.toArray());
50
+    }
51 51
 }

+ 13
- 12
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java 查看文件

@@ -1,35 +1,31 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import java.util.Iterator;
4
+import java.util.Spliterator;
3 5
 import java.util.Stack;
6
+import java.util.function.Consumer;
4 7
 
5 8
 /**
6 9
  * @author leon on 11/12/2018.
7 10
  */
8
-public class MyStack<SomeType> {
11
+public class MyStack<SomeType> implements Iterable<SomeType>{
9 12
 
10 13
     private Stack<SomeType> myStack = new Stack<>();
11 14
 
12 15
     public MyStack() {
13
-        try {
14
-            throw new UnsupportedOperationException("Method not yet implemented");
15
-        } catch (UnsupportedOperationException uoe){
16
-            uoe.printStackTrace();
17
-        }
18 16
     }
19 17
 
20 18
     public Boolean isEmpty() {
21 19
         return myStack.isEmpty();
22 20
     }
23 21
 
24
-    public void push(SomeType i) {
25
-        myStack.push(i);
22
+    public void push(SomeType i){
23
+            myStack.push(i);
26 24
     }
27 25
 
28 26
     public SomeType peek() {
29
-        try {
30
-            throw new UnsupportedOperationException("Method not yet implemented");
31
-        } catch (UnsupportedOperationException uoe){
32
-            uoe.printStackTrace();
27
+        if (myStack.isEmpty()){
28
+            return null;
33 29
         }
34 30
         return myStack.peek();
35 31
     }
@@ -37,4 +33,9 @@ public class MyStack<SomeType> {
37 33
     public SomeType pop() {
38 34
         return myStack.pop();
39 35
     }
36
+
37
+    @Override
38
+    public Iterator<SomeType> iterator() {
39
+        return myStack.iterator();
40
+    }
40 41
 }

+ 8
- 3
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java 查看文件

@@ -1,11 +1,16 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import javafx.collections.ObservableList;
4
+import javafx.collections.transformation.SortedList;
5
+
6
+import java.util.Collections;
7
+import java.util.HashSet;
8
+import java.util.Set;
9
+
3 10
 /**
4 11
  * @author leon on 18/12/2018.
5 12
  */
6
-public class SortedGroup<_> extends Group<_> {
7
-
8
-
13
+public class SortedGroup<_> extends Group<_> implements Iterable<_>, GroupInterface<_>{
9 14
 
10 15
     @Override
11 16
     public void insert(_ value) {

+ 6
- 4
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java 查看文件

@@ -5,21 +5,23 @@ import rocks.zipcode.io.quiz4.fundamentals.PalindromeEvaluator;
5 5
 /**
6 6
  * @author leon on 18/12/2018.
7 7
  */
8
-public class PalindromeObject {
8
+public class PalindromeObject extends PalindromeEvaluator {
9
+    private Object input;
9 10
     public PalindromeObject(String input) {
11
+        this.input = input;
10 12
     }
11 13
 
12 14
     public String[] getAllPalindromes(){
13 15
 
14
-        return null;
16
+        return getAllPalindromes((String) input);
15 17
     }
16 18
 
17 19
     public Boolean isPalindrome(){
18
-        return null;
20
+        return isPalindrome((String) input);
19 21
     }
20 22
 
21 23
     public String reverseString(){
22 24
 
23
-        return null;
25
+        return reverseString((String) input);
24 26
     }
25 27
 }

+ 10
- 0
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java 查看文件

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