瀏覽代碼

142 of 234 test passing

William Brown 6 年之前
父節點
當前提交
adda3d4544

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

@@ -9,6 +9,8 @@ import java.util.TreeSet;
9 9
  */
10 10
 public class ComparableTreeSet<_> extends TreeSet implements Comparable {
11 11
 
12
+    TreeSet thisTree = this;
13
+
12 14
     public ComparableTreeSet(_... arr) {
13 15
         addAll(Arrays.asList(arr));
14 16
     }
@@ -17,15 +19,18 @@ public class ComparableTreeSet<_> extends TreeSet implements Comparable {
17 19
 
18 20
     }
19 21
 
20
-    public Integer compareTo(ComparableTreeSet<_> o) {
21
-        if(this.first().equals(o.first())){
22
-            return 0;
23
-        }
24
-        return -1;
22
+    public int compareTo(ComparableTreeSet<_> o) {
23
+        return thisTree.first().toString().compareTo(o.first().toString());
25 24
     }
26 25
 
27 26
     public String toString(){
28
-        return null;
27
+        String output = "[";
28
+        for(Object i : thisTree){
29
+            output = output + i + ", ";
30
+        }
31
+
32
+        output = output.substring(0, output.length() - 2) + "]";
33
+        return output;
29 34
     }
30 35
 
31 36
     @Override

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

@@ -23,11 +23,17 @@ public class ZipCodeWilmington {
23 23
 
24 24
     public void lecture(double numberOfHours) {
25 25
         for(Student i : students){
26
-            i.learn(numberOfHours/students.size());
26
+            i.learn(numberOfHours);
27 27
         }
28 28
     }
29 29
 
30 30
     public Map<Student, Double> getStudyMap() {
31
-        return null;
31
+
32
+        Map<Student, Double> map = new HashMap<>();
33
+
34
+        for(Student i : students){
35
+            map.put(i, i.getTotalStudyTime());
36
+        }
37
+        return map;
32 38
     }
33 39
 }

+ 1
- 10
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java 查看文件

@@ -7,16 +7,7 @@ import java.util.*;
7 7
  */
8 8
 public class StringEvaluator {
9 9
     public static String[] getAllPrefixes(String string) {
10
-
11
-        Set set = new TreeSet();
12
-
13
-        for(int i = 0; i < string.length(); i++){
14
-            for(int j = 0; j < string.length(); j++){
15
-                set.add(string.substring(i, j));
16
-            }
17
-        }
18
-
19
-        return (String[]) set.stream().toArray(String[]::new);
10
+        return null;
20 11
     }
21 12
 
22 13
     public static String[] getCommonPrefixes(String string1, String string2) {

+ 2
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java 查看文件

@@ -5,7 +5,7 @@ package rocks.zipcode.io.quiz4.objectorientation;
5 5
  */
6 6
 public class Student {
7 7
 
8
-    private Double totalStudyTime;
8
+    private Double totalStudyTime = 0.0;
9 9
     private Integer id;
10 10
 
11 11
     public Student() {
@@ -17,7 +17,7 @@ public class Student {
17 17
     }
18 18
 
19 19
     public void learn(Double amountOfHours) {
20
-        totalStudyTime =+ amountOfHours;
20
+        totalStudyTime = totalStudyTime + amountOfHours;
21 21
     }
22 22
 
23 23
     public Double getTotalStudyTime() {