浏览代码

did a few

Saurav Kamath 6 年前
父节点
当前提交
50e3651504

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

@@ -1,17 +1,32 @@
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<_> {
7
-    public ComparableTreeSet(_... arr) {
8
-    }
9
+public class ComparableTreeSet<T> extends TreeSet implements Comparable{
9 10
 
11
+    @SafeVarargs
12
+    public ComparableTreeSet(T... arr) {
10 13
 
14
+    }
11 15
     public ComparableTreeSet() {
12 16
     }
13 17
 
14
-    public Integer compareTo(ComparableTreeSet<_> o) {
18
+    public Integer compareTo(ComparableTreeSet<T> o) {
19
+
15 20
         return null;
16 21
     }
22
+
23
+    @Override
24
+    public int compareTo(Object o) {
25
+        return 0;
26
+    }
27
+
28
+    @Override
29
+    public String toString() {
30
+       return Arrays.toString(this.toArray());
31
+    }
17 32
 }

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

@@ -1,31 +1,59 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Iterator;
5
+import java.util.NoSuchElementException;
6
+
3 7
 /**
4 8
  * @author leon on 11/12/2018.
5 9
  */
6
-public class SimpleStringGroup {
10
+public class SimpleStringGroup implements Iterable {
11
+    private ArrayList<String> list = new ArrayList<>();
12
+
7 13
     public SimpleStringGroup() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
14
+
9 15
     }
10 16
 
11 17
     public Integer count() {
12
-        return null;
18
+        return list.size();
13 19
     }
14 20
 
15 21
     public void insert(String string) {
22
+        list.add(string);
16 23
     }
17 24
 
18 25
     public Boolean has(String valueToInsert) {
19
-        return null;
26
+        return list.contains(valueToInsert);
20 27
     }
21 28
 
22 29
     public String fetch(int indexOfValue) {
23
-        return null;
30
+        return list.get(indexOfValue);
24 31
     }
25 32
 
26 33
     public void delete(String valueToInsert) {
34
+        list.remove(valueToInsert);
27 35
     }
28 36
 
29 37
     public void clear() {
38
+        list.clear();
39
+    }
40
+
41
+    @Override
42
+    public Iterator iterator() {
43
+        return new Iterator() {
44
+            int i = 0;
45
+            @Override
46
+            public boolean hasNext() {
47
+                return i < list.size();
48
+            }
49
+            @Override
50
+            public Object next() {
51
+                if (!hasNext()) {
52
+                    throw new NoSuchElementException("blank");
53
+                } else {
54
+                    return list.get(i++);
55
+                }
56
+            }
57
+        };
30 58
     }
31 59
 }

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

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

+ 3
- 0
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java 查看文件

@@ -5,6 +5,9 @@ package rocks.zipcode.io.quiz4.fundamentals;
5 5
  */
6 6
 public class PalindromeEvaluator {
7 7
     public static String[] getAllPalindromes(String string) {
8
+
9
+
10
+
8 11
         return null;
9 12
     }
10 13
 

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

@@ -4,17 +4,22 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 11/12/2018.
5 5
  */
6 6
 public class Student {
7
+    Integer id;
8
+    Double hoursTaught;
9
+
7 10
     public Student() {
8 11
         this(null);
9 12
     }
10 13
 
11 14
     public Student(Integer id) {
15
+        this.id = id;
12 16
     }
13 17
 
14 18
     public void learn(Double amountOfHours) {
19
+        hoursTaught += amountOfHours;
15 20
     }
16 21
 
17 22
     public Double getTotalStudyTime() {
18
-        return null;
23
+        return hoursTaught;
19 24
     }
20 25
 }

+ 2
- 1
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/EnrollTest.java 查看文件

@@ -18,7 +18,8 @@ public class EnrollTest {
18 18
     public void test2() {
19 19
         test(
20 20
                 new Student(),
21
-                new Student());
21
+                new Student()
22
+        );
22 23
     }
23 24
 
24 25
     @Test