Saurav Kamath 6 lat temu
rodzic
commit
50e3651504

+ 19
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java Wyświetl plik

1
 package rocks.zipcode.io.quiz4.collections;
1
 package rocks.zipcode.io.quiz4.collections;
2
 
2
 
3
+import java.util.Arrays;
4
+import java.util.TreeSet;
5
+
3
 /**
6
 /**
4
  * @author leon on 11/12/2018.
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
     public ComparableTreeSet() {
15
     public ComparableTreeSet() {
12
     }
16
     }
13
 
17
 
14
-    public Integer compareTo(ComparableTreeSet<_> o) {
18
+    public Integer compareTo(ComparableTreeSet<T> o) {
19
+
15
         return null;
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 Wyświetl plik

1
 package rocks.zipcode.io.quiz4.collections;
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
  * @author leon on 11/12/2018.
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
     public SimpleStringGroup() {
13
     public SimpleStringGroup() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
14
+
9
     }
15
     }
10
 
16
 
11
     public Integer count() {
17
     public Integer count() {
12
-        return null;
18
+        return list.size();
13
     }
19
     }
14
 
20
 
15
     public void insert(String string) {
21
     public void insert(String string) {
22
+        list.add(string);
16
     }
23
     }
17
 
24
 
18
     public Boolean has(String valueToInsert) {
25
     public Boolean has(String valueToInsert) {
19
-        return null;
26
+        return list.contains(valueToInsert);
20
     }
27
     }
21
 
28
 
22
     public String fetch(int indexOfValue) {
29
     public String fetch(int indexOfValue) {
23
-        return null;
30
+        return list.get(indexOfValue);
24
     }
31
     }
25
 
32
 
26
     public void delete(String valueToInsert) {
33
     public void delete(String valueToInsert) {
34
+        list.remove(valueToInsert);
27
     }
35
     }
28
 
36
 
29
     public void clear() {
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 Wyświetl plik

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

5
  */
5
  */
6
 public class PalindromeEvaluator {
6
 public class PalindromeEvaluator {
7
     public static String[] getAllPalindromes(String string) {
7
     public static String[] getAllPalindromes(String string) {
8
+
9
+
10
+
8
         return null;
11
         return null;
9
     }
12
     }
10
 
13
 

+ 6
- 1
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java Wyświetl plik

4
  * @author leon on 11/12/2018.
4
  * @author leon on 11/12/2018.
5
  */
5
  */
6
 public class Student {
6
 public class Student {
7
+    Integer id;
8
+    Double hoursTaught;
9
+
7
     public Student() {
10
     public Student() {
8
         this(null);
11
         this(null);
9
     }
12
     }
10
 
13
 
11
     public Student(Integer id) {
14
     public Student(Integer id) {
15
+        this.id = id;
12
     }
16
     }
13
 
17
 
14
     public void learn(Double amountOfHours) {
18
     public void learn(Double amountOfHours) {
19
+        hoursTaught += amountOfHours;
15
     }
20
     }
16
 
21
 
17
     public Double getTotalStudyTime() {
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 Wyświetl plik

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