Browse Source

completed quiz 4

Jonathan Hinds 6 years ago
parent
commit
dde1ef28f5
21 changed files with 330 additions and 89 deletions
  1. 5
    40
      src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java
  2. 39
    6
      src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java
  3. 20
    4
      src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java
  4. 42
    3
      src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java
  5. 44
    4
      src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java
  6. 31
    4
      src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java
  7. 40
    8
      src/main/java/rocks/zipcode/io/quiz4/generics/Group.java
  8. 21
    5
      src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java
  9. 7
    2
      src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java
  10. 15
    3
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java
  11. 18
    2
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java
  12. 9
    3
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java
  13. 19
    3
      src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java
  14. 1
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementNegative.java
  15. 1
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementPositive.java
  16. 1
    1
      src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/CountTest.java
  17. 2
    0
      src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/GetStudyMapTest.java
  18. 11
    0
      src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetAllPrefixes.java
  19. 2
    0
      src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupInsertTest.java
  20. 1
    1
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectIsPalindromeTestNegative.java
  21. 1
    0
      src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringassembler/AppendTest.java

+ 5
- 40
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java View File

7
 /**
7
 /**
8
  * @author leon on 11/12/2018.
8
  * @author leon on 11/12/2018.
9
  */
9
  */
10
-public class ComparableTreeSet<_ extends Comparable<? super _>> implements Comparable<Object> {
11
-
12
-    private Set<_> arr;
10
+public class ComparableTreeSet<_ extends Comparable<? super _>> extends TreeSet<_> implements Comparable<ComparableTreeSet<_>> {
13
 
11
 
14
     public ComparableTreeSet(_... arr) {
12
     public ComparableTreeSet(_... arr) {
15
-        this.arr = new TreeSet<_>(Arrays.asList(arr));;
13
+        super(Arrays.asList(arr));
16
     }
14
     }
17
 
15
 
18
     public ComparableTreeSet(Set<_> set) {
16
     public ComparableTreeSet(Set<_> set) {
19
-        this.arr = set;
17
+        super.addAll(set);
20
     }
18
     }
21
 
19
 
22
     public ComparableTreeSet() {
20
     public ComparableTreeSet() {
23
     }
21
     }
24
 
22
 
25
-    public Integer compareTo(ComparableTreeSet<_> o) {
26
-        Integer count = 0;
27
-        Integer counter = 0;
28
-        Integer counter2 = 0;
29
-
30
-        for(_ element : arr){
31
-            for(_ element2 : o.getArr()){
32
-                if(counter.equals(counter2)){
33
-                    if(element.compareTo(element2) < 1){
34
-                        count ++;
35
-                        counter2 ++;
36
-                        break;
37
-                    } else if (element.compareTo(element2) > 1){
38
-                        count --;
39
-                        counter2 ++;
40
-                        break;
41
-                    } else {
42
-                        counter2 ++;
43
-                        break;
44
-                    }
45
-                }
46
-            }
47
-            counter ++;
48
-        }
49
-        System.out.println(count);
50
-        return count;
51
-    }
52
-
53
-    public Set<_> getArr() {
54
-        return arr;
55
-    }
56
-
57
-    @Override
58
-    public int compareTo(Object o) {
59
-        return 0;
23
+    public int compareTo(ComparableTreeSet<_> o) {
24
+        return this.first().compareTo(o.first());
60
     }
25
     }
61
 }
26
 }

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

1
 package rocks.zipcode.io.quiz4.collections;
1
 package rocks.zipcode.io.quiz4.collections;
2
 
2
 
3
+import java.util.*;
4
+import java.util.function.Consumer;
5
+
3
 /**
6
 /**
4
  * @author leon on 11/12/2018.
7
  * @author leon on 11/12/2018.
5
  */
8
  */
6
-public class SimpleStringGroup {
7
-    public SimpleStringGroup() {
8
-        throw new UnsupportedOperationException("Method not yet implemented");
9
+public class SimpleStringGroup implements Iterable<String>{
10
+
11
+    List<String> group = new ArrayList<>();
12
+
13
+    public SimpleStringGroup(String... args) {
14
+        group.addAll(Arrays.asList(args));
9
     }
15
     }
10
 
16
 
11
     public Integer count() {
17
     public Integer count() {
12
-        return null;
18
+        System.out.println(group.size());
19
+        return group.size();
13
     }
20
     }
14
 
21
 
15
     public void insert(String string) {
22
     public void insert(String string) {
23
+        group.add(string);
16
     }
24
     }
17
 
25
 
18
     public Boolean has(String valueToInsert) {
26
     public Boolean has(String valueToInsert) {
19
-        return null;
27
+
28
+        for(String elm : group){
29
+            if(elm.equals(valueToInsert)){
30
+                return true;
31
+            }
32
+        }
33
+        return false;
20
     }
34
     }
21
 
35
 
22
     public String fetch(int indexOfValue) {
36
     public String fetch(int indexOfValue) {
23
-        return null;
37
+        return group.get(indexOfValue);
24
     }
38
     }
25
 
39
 
26
     public void delete(String valueToInsert) {
40
     public void delete(String valueToInsert) {
41
+        group.remove(valueToInsert);
27
     }
42
     }
28
 
43
 
29
     public void clear() {
44
     public void clear() {
45
+        group = new ArrayList<>();
46
+    }
47
+
48
+    @Override
49
+    public Iterator<String> iterator() {
50
+        return group.iterator();
51
+    }
52
+
53
+    @Override
54
+    public void forEach(Consumer<? super String> action) {
55
+        for(String arg : group){
56
+            action.accept(arg);
57
+        }
58
+    }
59
+
60
+    @Override
61
+    public Spliterator<String> spliterator() {
62
+        return null;
30
     }
63
     }
31
 }
64
 }

+ 20
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java View File

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

+ 42
- 3
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java View File

1
 package rocks.zipcode.io.quiz4.fundamentals;
1
 package rocks.zipcode.io.quiz4.fundamentals;
2
 
2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+import java.util.List;
6
+
3
 /**
7
 /**
4
  * @author leon on 18/12/2018.
8
  * @author leon on 18/12/2018.
5
  */
9
  */
6
 public class PalindromeEvaluator {
10
 public class PalindromeEvaluator {
7
     public static String[] getAllPalindromes(String string) {
11
     public static String[] getAllPalindromes(String string) {
8
-        return null;
12
+        String[] substrings = StringEvaluator.getAllPrefixes(string);
13
+        List<String> pal = new ArrayList<>();
14
+
15
+        for(String in : substrings){
16
+            if(isPalindrome(in)){
17
+                pal.add(in);
18
+            }
19
+        }
20
+
21
+        return pal.toArray(new String[pal.size()]);
9
     }
22
     }
10
 
23
 
11
     public static Boolean isPalindrome(String string) {
24
     public static Boolean isPalindrome(String string) {
12
-        return null;
25
+
26
+        String[] word = string.split("");
27
+
28
+        int counter1 = 0;
29
+        int counter2 = word.length - 1;
30
+        while (counter2 > counter1) {
31
+            System.out.println(word[counter1] + " " + word[counter2]);
32
+            if (!word[counter1].equals(word[counter2])) {
33
+                return false;
34
+            }
35
+            ++counter1;
36
+            --counter2;
37
+        }
38
+        return true;
39
+
13
     }
40
     }
14
 
41
 
15
     public static String reverseString(String string) {
42
     public static String reverseString(String string) {
16
-        return null;
43
+        String[] chars = string.split("");
44
+        String result = "";
45
+        for(int i = 0; i < chars.length / 2; i ++){
46
+            String temp = chars[i];
47
+            chars[i] = chars[chars.length - i - 1];
48
+            chars[chars.length - i - 1] = temp;
49
+        }
50
+
51
+        for(String character : chars){
52
+            result += character;
53
+        }
54
+
55
+        return result;
17
     }
56
     }
18
 }
57
 }

+ 44
- 4
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java View File

1
 package rocks.zipcode.io.quiz4.fundamentals;
1
 package rocks.zipcode.io.quiz4.fundamentals;
2
 
2
 
3
+import java.util.*;
4
+
3
 /**
5
 /**
4
  * @author leon on 11/12/2018.
6
  * @author leon on 11/12/2018.
5
  */
7
  */
6
 public class StringEvaluator {
8
 public class StringEvaluator {
7
-    public static String[] getAllPrefixes(String string) {
8
-        return null;
9
+    public static String[] getAllPrefixes(String string)
10
+    {
11
+        List<String> list = new ArrayList<>();
12
+        Set<String> set = new HashSet<>();
13
+
14
+        for (int i = 0; i < string.toCharArray().length; i++) {
15
+            for (int j = i + 1; j <= string.toCharArray().length; j++) {
16
+                set.add(string.substring(i, j));
17
+                //System.out.println(i + " " + j + ": " + string.substring(i, j));
18
+            }
19
+        }
20
+
21
+        //System.out.println(Arrays.toString(list.toArray(new String[list.size()])));
22
+
23
+        return set.toArray(new String[list.size()]);
9
     }
24
     }
10
 
25
 
11
     public static String[] getCommonPrefixes(String string1, String string2) {
26
     public static String[] getCommonPrefixes(String string1, String string2) {
12
-        return null;
27
+        List<String> returnList = new ArrayList<>();
28
+        Set<String> set = new HashSet<>();
29
+
30
+        String[] sufix1 = getAllPrefixes(string1);
31
+        List<String> list1 = Arrays.asList(sufix1);
32
+
33
+        String[] sufix2 = getAllPrefixes(string2);
34
+        List<String> list2 = Arrays.asList(sufix2);
35
+
36
+        for(String element : list1){
37
+            if(list2.contains(element)){
38
+                set.add(element);
39
+            }
40
+        }
41
+
42
+        System.out.println(Arrays.toString(set.toArray(new String[returnList.size()])));
43
+        return set.toArray(new String[returnList.size()]);
13
     }
44
     }
14
 
45
 
15
     public static String getLargestCommonPrefix(String string1, String string2) {
46
     public static String getLargestCommonPrefix(String string1, String string2) {
16
-        return null;
47
+        String[] common = getCommonPrefixes(string1, string2);
48
+        int max = common[0].toCharArray().length;
49
+        String word = common[0];
50
+        for(String string : common){
51
+            if(max < string.toCharArray().length){
52
+                max = string.toCharArray().length;
53
+                word = string;
54
+            }
55
+        }
56
+        return word;
17
     }
57
     }
18
 }
58
 }

+ 31
- 4
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java View File

1
 package rocks.zipcode.io.quiz4.generics;
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.lang.reflect.Array;
4
+import java.util.*;
6
 
5
 
7
 /**
6
 /**
8
  * @author leon on 11/12/2018.
7
  * @author leon on 11/12/2018.
9
  */
8
  */
10
 public class GenericUtils {
9
 public class GenericUtils {
11
     public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
10
     public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
12
-        return null;
11
+
12
+        List<Iterable<_>> powerSet = new ArrayList<>();
13
+        List<_> allelms = new ArrayList<>(originalSet);
14
+        powerSet.add(allelms);
15
+
16
+        int counter = 0;
17
+        int counter2 = 0;
18
+
19
+        for(_ elm : originalSet){
20
+            counter2 = 0;
21
+            for(_ elm2 : originalSet){
22
+                List<_> subset = new ArrayList<>();
23
+                if(counter == counter2){
24
+                } else {
25
+                    subset.add(elm);
26
+                    subset.add(elm2);
27
+                    Iterable<_> it2 = subset;
28
+                    powerSet.add(it2);
29
+                }
30
+                counter2 ++;
31
+            }
32
+            List<_> list = new ArrayList<>();
33
+            list.add(elm);
34
+            Iterable<_> it = list;
35
+            powerSet.add(it);
36
+            counter ++;
37
+        }
38
+        powerSet.add(new ArrayList<>());
39
+        return powerSet;
13
     }
40
     }
14
 
41
 
15
     public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(_... originalSet) {
42
     public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(_... originalSet) {

+ 40
- 8
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java View File

1
 package rocks.zipcode.io.quiz4.generics;
1
 package rocks.zipcode.io.quiz4.generics;
2
 
2
 
3
+import java.util.ArrayList;
4
+import java.util.Collection;
3
 import java.util.Iterator;
5
 import java.util.Iterator;
6
+import java.util.List;
4
 
7
 
5
 /**
8
 /**
6
  * @author leon on 18/12/2018.
9
  * @author leon on 18/12/2018.
7
  */
10
  */
8
-public class Group<_> {
11
+public class Group<_> implements GroupInterface<_> {
12
+
13
+    List<_> group = new ArrayList<>();
14
+
9
     public Group() {
15
     public Group() {
10
-        throw new UnsupportedOperationException("Method not yet implemented");
11
     }
16
     }
12
 
17
 
13
     public Integer count() {
18
     public Integer count() {
14
-        return null;
19
+
20
+        return group.size();
15
     }
21
     }
16
 
22
 
17
-    public void insert(_ value) {
23
+    public Integer indexOf(_ value){
24
+        for(int i = 0; i < group.size(); i ++){
25
+            if(group.get(i).equals(value)){
26
+                return i;
27
+            }
28
+        }
29
+        return -1;
18
     }
30
     }
19
 
31
 
32
+    @Override
20
     public Boolean has(_ value) {
33
     public Boolean has(_ value) {
21
-        return null;
34
+        for(_ elm : group){
35
+            if(elm.equals(value)){
36
+                return true;
37
+            }
38
+        }
39
+        return false;
22
     }
40
     }
23
 
41
 
24
     public _ fetch(int indexOfValue) {
42
     public _ fetch(int indexOfValue) {
25
-        return null;
43
+        return group.get(indexOfValue);
26
     }
44
     }
27
 
45
 
28
-    public void delete(_ value) {
46
+    @Override
47
+    public void insert(_ value) {
48
+        group.add(value);
49
+    }
50
+
51
+    @Override
52
+    public void delete(_ valueToInsert) {
53
+        group.remove(valueToInsert);
29
     }
54
     }
30
 
55
 
31
     public void clear() {
56
     public void clear() {
57
+        group = new ArrayList<>();
32
     }
58
     }
33
 
59
 
60
+    @Override
34
     public Iterator<_> iterator() {
61
     public Iterator<_> iterator() {
35
-        return null;
62
+        return group.iterator();
63
+    }
64
+
65
+    @Override
66
+    public String toString() {
67
+        return "" + group ;
36
     }
68
     }
37
 }
69
 }

+ 21
- 5
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java View File

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

+ 7
- 2
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java View File

1
 package rocks.zipcode.io.quiz4.generics;
1
 package rocks.zipcode.io.quiz4.generics;
2
 
2
 
3
+import java.util.Collections;
4
+
3
 /**
5
 /**
4
  * @author leon on 18/12/2018.
6
  * @author leon on 18/12/2018.
5
  */
7
  */
6
-public class SortedGroup<_> extends Group<_> {
8
+public class SortedGroup<_ extends  Comparable<_>> extends Group<_> {
7
     @Override
9
     @Override
8
     public void insert(_ value) {
10
     public void insert(_ value) {
11
+        super.insert(value);
12
+        Collections.sort(super.group);
9
     }
13
     }
10
 
14
 
11
     @Override
15
     @Override
12
     public void delete(_ value) {
16
     public void delete(_ value) {
17
+        super.delete(value);
13
     }
18
     }
14
 
19
 
15
     public Integer indexOf(_ firstValue) {
20
     public Integer indexOf(_ firstValue) {
16
-        return null;
21
+        return super.indexOf(firstValue);
17
     }
22
     }
18
 }
23
 }

+ 15
- 3
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java View File

1
 package rocks.zipcode.io.quiz4.objectorientation;
1
 package rocks.zipcode.io.quiz4.objectorientation;
2
 
2
 
3
+import rocks.zipcode.io.quiz4.fundamentals.PalindromeEvaluator;
4
+
3
 /**
5
 /**
4
  * @author leon on 18/12/2018.
6
  * @author leon on 18/12/2018.
5
  */
7
  */
6
 public class PalindromeObject {
8
 public class PalindromeObject {
9
+
10
+    String eval;
11
+
7
     public PalindromeObject(String input) {
12
     public PalindromeObject(String input) {
13
+        eval = input;
14
+    }
15
+
16
+    public PalindromeObject() {
8
     }
17
     }
9
 
18
 
10
     public String[] getAllPalindromes(){
19
     public String[] getAllPalindromes(){
11
-        return null;
20
+
21
+        return PalindromeEvaluator.getAllPalindromes(eval);
12
     }
22
     }
13
 
23
 
14
     public Boolean isPalindrome(){
24
     public Boolean isPalindrome(){
15
-        return null;
25
+
26
+        return PalindromeEvaluator.isPalindrome(eval);
16
     }
27
     }
17
 
28
 
18
     public String reverseString(){
29
     public String reverseString(){
19
-        return null;
30
+
31
+        return PalindromeEvaluator.reverseString(eval);
20
     }
32
     }
21
 }
33
 }

+ 18
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java View File

1
 package rocks.zipcode.io.quiz4.objectorientation;
1
 package rocks.zipcode.io.quiz4.objectorientation;
2
 
2
 
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
3
 /**
6
 /**
4
  * @author leon on 11/12/2018.
7
  * @author leon on 11/12/2018.
5
  */
8
  */
6
 public class StringAssembler {
9
 public class StringAssembler {
10
+
11
+    Character delimiter;
12
+    List<String> words = new ArrayList<>();
13
+
7
     public StringAssembler(Character delimeter) {
14
     public StringAssembler(Character delimeter) {
15
+        this.delimiter = delimeter;
8
     }
16
     }
9
 
17
 
10
     public StringAssembler append(String str) {
18
     public StringAssembler append(String str) {
11
-        return null;
19
+        words.add(str);
20
+        return this;
12
     }
21
     }
13
 
22
 
14
     public String assemble() {
23
     public String assemble() {
15
-        return null;
24
+        String result = "";
25
+        for(int i = 0; i < words.size(); i ++){
26
+            result += words.get(i);
27
+            if(!(i == words.size() - 1)){
28
+                result += String.valueOf(delimiter);
29
+            }
30
+        }
31
+        return result;
16
     }
32
     }
17
 }
33
 }

+ 9
- 3
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java View File

1
 package rocks.zipcode.io.quiz4.objectorientation;
1
 package rocks.zipcode.io.quiz4.objectorientation;
2
 
2
 
3
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
4
+
3
 /**
5
 /**
4
  * @author leon on 19/12/2018.
6
  * @author leon on 19/12/2018.
5
  */
7
  */
6
 public class StringEvaluatorObject {
8
 public class StringEvaluatorObject {
9
+
10
+    String evaluate;
11
+
7
     public StringEvaluatorObject(String str) {
12
     public StringEvaluatorObject(String str) {
13
+        evaluate = str;
8
     }
14
     }
9
 
15
 
10
     public String[] getAllPrefixes() {
16
     public String[] getAllPrefixes() {
11
-        return null;
17
+        return StringEvaluator.getAllPrefixes(evaluate);
12
     }
18
     }
13
 
19
 
14
     public String[] getCommonPrefixes(String secondInput) {
20
     public String[] getCommonPrefixes(String secondInput) {
15
-        return null;
21
+        return StringEvaluator.getCommonPrefixes(evaluate, secondInput);
16
     }
22
     }
17
 
23
 
18
     public String getLargestCommonPrefix(String secondInput) {
24
     public String getLargestCommonPrefix(String secondInput) {
19
-        return null;
25
+        return StringEvaluator.getLargestCommonPrefix(evaluate, secondInput);
20
     }
26
     }
21
 }
27
 }

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

3
 /**
3
 /**
4
  * @author leon on 11/12/2018.
4
  * @author leon on 11/12/2018.
5
  */
5
  */
6
-public class Student {
6
+public class Student implements Comparable<Student>{
7
+
8
+    Double totalStudyTime = 0.0;
9
+    private static int lastID = 0;
10
+    Integer id;
11
+
7
     public Student() {
12
     public Student() {
8
-        this(null);
13
+        this(lastID ++);
9
     }
14
     }
10
 
15
 
11
     public Student(Integer id) {
16
     public Student(Integer id) {
17
+        this.id = id;
12
     }
18
     }
13
 
19
 
14
     public void learn(Double amountOfHours) {
20
     public void learn(Double amountOfHours) {
21
+        totalStudyTime += amountOfHours;
15
     }
22
     }
16
 
23
 
17
     public Double getTotalStudyTime() {
24
     public Double getTotalStudyTime() {
18
-        return null;
25
+        return totalStudyTime;
26
+    }
27
+
28
+    @Override
29
+    public int compareTo(Student o) {
30
+        return id.compareTo(o.getId());
31
+    }
32
+
33
+    public Integer getId() {
34
+        return id;
19
     }
35
     }
20
 }
36
 }

+ 1
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementNegative.java View File

40
 
40
 
41
         // when
41
         // when
42
         Integer actual = powerset1.compareTo(powerset2);
42
         Integer actual = powerset1.compareTo(powerset2);
43
+        System.out.println(actual);
43
 
44
 
44
         // then
45
         // then
45
         Assert.assertTrue(actual < 0);
46
         Assert.assertTrue(actual < 0);

+ 1
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/comparabletreeset/compareto/nestedset/multipleelement/NestedSetCompareMultipleElementPositive.java View File

21
 
21
 
22
         // when
22
         // when
23
         Integer actual = powerset1.compareTo(powerset2);
23
         Integer actual = powerset1.compareTo(powerset2);
24
+        System.out.println(actual);
24
 
25
 
25
         // then
26
         // then
26
         Assert.assertTrue(actual > 0);
27
         Assert.assertTrue(actual > 0);

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz4/collections/simplestringgroup/CountTest.java View File

37
         }
37
         }
38
 
38
 
39
         // then
39
         // then
40
-        Assert.assertEquals(group.count(), numberOfItemsToAdd);
40
+        Assert.assertEquals(numberOfItemsToAdd, group.count());
41
     }
41
     }
42
 }
42
 }

+ 2
- 0
src/test/java/rocks/zipcode/io/quiz4/collections/zipcodewilmington/GetStudyMapTest.java View File

30
         Map.Entry<Student, Double> firstEntry = entrySet.get(0);
30
         Map.Entry<Student, Double> firstEntry = entrySet.get(0);
31
 
31
 
32
         Student actualStudent1 = firstEntry.getKey();
32
         Student actualStudent1 = firstEntry.getKey();
33
+        System.out.println(actualStudent1);
33
         Double actualStudyTime1 = firstEntry.getValue();
34
         Double actualStudyTime1 = firstEntry.getValue();
35
+        System.out.println(actualStudyTime1);
34
 
36
 
35
 
37
 
36
 
38
 

+ 11
- 0
src/test/java/rocks/zipcode/io/quiz4/fundamentals/stringevaluator/GetAllPrefixes.java View File

4
 import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
4
 import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
5
 import rocks.zipcode.io.quiz4.utils.TestUtils;
5
 import rocks.zipcode.io.quiz4.utils.TestUtils;
6
 
6
 
7
+import java.util.Arrays;
8
+
7
 /**
9
 /**
8
  * @author leon on 11/12/2018.
10
  * @author leon on 11/12/2018.
9
  */
11
  */
62
         TestUtils.assertArrayEquals(expected, actual);
64
         TestUtils.assertArrayEquals(expected, actual);
63
     }
65
     }
64
 
66
 
67
+    /*
68
+        1: A
69
+        0 2: AB
70
+        0 3: ABB
71
+        1 2: B
72
+        1 3: BB
73
+        2 3: B
74
+     */
75
+
65
 
76
 
66
     @Test
77
     @Test
67
     public void test5() {
78
     public void test5() {

+ 2
- 0
src/test/java/rocks/zipcode/io/quiz4/generics/sortedgroup/integersortedgroup/IntegerSortedGroupInsertTest.java View File

30
         int thirdValueIndex = group.indexOf(thirdValue);
30
         int thirdValueIndex = group.indexOf(thirdValue);
31
         int fourthValueIndex = group.indexOf(fourthValue);
31
         int fourthValueIndex = group.indexOf(fourthValue);
32
 
32
 
33
+        System.out.println(group.toString());
34
+
33
         // then
35
         // then
34
         Assert.assertEquals(firstValueIndex, 0);
36
         Assert.assertEquals(firstValueIndex, 0);
35
         Assert.assertEquals(secondValueIndex, 1);
37
         Assert.assertEquals(secondValueIndex, 1);

+ 1
- 1
src/test/java/rocks/zipcode/io/quiz4/objectorientation/palindromeobject/PalindromeObjectIsPalindromeTestNegative.java View File

25
     }
25
     }
26
 
26
 
27
     public void test(String input) {
27
     public void test(String input) {
28
-        Assert.assertTrue(new PalindromeObject(input).isPalindrome());
28
+        Assert.assertFalse(new PalindromeObject(input).isPalindrome());
29
     }
29
     }
30
 }
30
 }

+ 1
- 0
src/test/java/rocks/zipcode/io/quiz4/objectorientation/stringassembler/AppendTest.java View File

24
                 .assemble();
24
                 .assemble();
25
 
25
 
26
         // then
26
         // then
27
+
27
         Assert.assertEquals(expected, actual);
28
         Assert.assertEquals(expected, actual);
28
     }
29
     }
29
 
30