Elliott Stansbury преди 5 години
родител
ревизия
e891971367

+ 2
- 2
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java Целия файл

@@ -11,7 +11,7 @@ public class ComparableTreeSet<_> {
11 11
     public ComparableTreeSet() {
12 12
     }
13 13
 
14
-    public Integer compareTo(ComparableTreeSet<_> o) {
15
-        return null;
14
+    public int compareTo(ComparableTreeSet<_> o) {
15
+        return 0;
16 16
     }
17 17
 }

+ 29
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java Целия файл

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

+ 34
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java Целия файл

@@ -2,23 +2,53 @@ package rocks.zipcode.io.quiz4.collections;
2 2
 
3 3
 import rocks.zipcode.io.quiz4.objectorientation.Student;
4 4
 
5
-import java.util.Map;
5
+import java.util.*;
6 6
 
7 7
 /**
8 8
  * @author leon on 11/12/2018.
9 9
  */
10
-public class ZipCodeWilmington {
10
+public class ZipCodeWilmington extends ArrayList<Student> {
11
+
12
+    ArrayList<Student> zipCodeWilmington = new ArrayList<Student>();
13
+
14
+    Student student = new Student();
15
+
16
+    HashMap hashMap = new HashMap();
17
+
18
+
11 19
     public void enroll(Student student) {
20
+        zipCodeWilmington.add(student);
21
+
12 22
     }
13 23
 
14 24
     public Boolean isEnrolled(Student student) {
15
-        return null;
25
+
26
+        if(zipCodeWilmington.contains(student)){
27
+            return true;
28
+        }
29
+
30
+        return false;
16 31
     }
17 32
 
18 33
     public void lecture(double numberOfHours) {
34
+
35
+        for(Student s : zipCodeWilmington){
36
+            s.learn(numberOfHours);
37
+        }
38
+
19 39
     }
20 40
 
21 41
     public Map<Student, Double> getStudyMap() {
22
-        return null;
42
+
43
+
44
+        for(Student s : zipCodeWilmington){
45
+            hashMap.put(s,s.getTotalStudyTime().doubleValue());
46
+            System.out.println(s.getTotalStudyTime());
47
+
48
+        }
49
+
50
+
51
+
52
+        return hashMap;
23 53
     }
24 54
 }

+ 40
- 3
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java Целия файл

@@ -1,18 +1,55 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import java.util.HashSet;
4
+import java.util.Set;
5
+
3 6
 /**
4 7
  * @author leon on 18/12/2018.
5 8
  */
6 9
 public class PalindromeEvaluator {
7 10
     public static String[] getAllPalindromes(String string) {
8
-        return null;
11
+
12
+        Set<CharSequence> stringSet = new HashSet<>();
13
+
14
+        for(int i =1; i <= string.length();i++){
15
+            for(int j =i; j<string.length(); j++){
16
+                if(isPalindrome(string.substring(i, j+1))){
17
+                    stringSet.add(string.substring(i,j+1));
18
+                }
19
+            }
20
+        }
21
+
22
+        stringSet.add(string);
23
+
24
+        return stringSet.toArray(new String[0]);
9 25
     }
10 26
 
11 27
     public static Boolean isPalindrome(String string) {
12
-        return null;
28
+
29
+        StringBuilder builder = new StringBuilder();
30
+        builder.append(string);
31
+
32
+        String reversedString = builder.reverse().toString();
33
+
34
+        for(int i = 0; i < string.length()/2; i++){
35
+            if(string.charAt(i) != string.charAt(string.length()-1-i)){
36
+                return false;
37
+            }else if(!reverseString(string).equals(reversedString)){
38
+                return false;
39
+            }
40
+        }
41
+
42
+        return true;
13 43
     }
14 44
 
15 45
     public static String reverseString(String string) {
16
-        return null;
46
+
47
+        StringBuilder builder = new StringBuilder();
48
+
49
+        builder.append(string);
50
+
51
+        builder = builder.reverse();
52
+
53
+        return builder.toString();
17 54
     }
18 55
 }

+ 53
- 3
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java Целия файл

@@ -1,18 +1,68 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.HashSet;
5
+import java.util.List;
6
+
3 7
 /**
4 8
  * @author leon on 11/12/2018.
5 9
  */
6 10
 public class StringEvaluator {
7 11
     public static String[] getAllPrefixes(String string) {
8
-        return null;
12
+
13
+        HashSet<String> stringSet = new HashSet<>();
14
+
15
+        if(string.length() == 1){
16
+            Character letter = string.charAt(0);
17
+            stringSet.add(letter.toString());
18
+        }
19
+        else {
20
+
21
+            for(int i = 0; i < string.length(); i++){
22
+                for(int j = 1; j <= string.length()-i; j++){
23
+                    String sub = string.substring(i, i+j);
24
+                    stringSet.add(sub);
25
+                }
26
+            }
27
+        }
28
+
29
+        String[] strings = stringSet.toArray(new String[0]);
30
+        return strings;
9 31
     }
10 32
 
11 33
     public static String[] getCommonPrefixes(String string1, String string2) {
12
-        return null;
34
+
35
+        String[] string1Array = getAllPrefixes(string1);
36
+        String[] string2Array = getAllPrefixes(string2);
37
+
38
+        List<String> list = new ArrayList<>();
39
+
40
+        for(int i = 0; i < string1Array.length; i++){
41
+            for(int j = 0; j < string2Array.length; j++){
42
+                if(string1Array[i].equals(string2Array[j])){
43
+                        list.add(string1Array[i]);
44
+                }
45
+            }
46
+        }
47
+
48
+        return list.toArray(new String[0]);
13 49
     }
14 50
 
15 51
     public static String getLargestCommonPrefix(String string1, String string2) {
16
-        return null;
52
+
53
+        String[] commonPrefixes = getCommonPrefixes(string1,string2);
54
+
55
+        int index = 0;
56
+        int stringLength = commonPrefixes[0].length();
57
+
58
+
59
+        for(int i = 1; i <= commonPrefixes.length-1; i++){
60
+            if(commonPrefixes[i].length() > stringLength){
61
+                index = i;
62
+                stringLength = commonPrefixes[i].length();
63
+            }
64
+        }
65
+
66
+        return commonPrefixes[index];
17 67
     }
18 68
 }

+ 26
- 4
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java Целия файл

@@ -1,28 +1,50 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.Iterator;
5
+import java.util.LinkedList;
6
+import java.util.List;
4 7
 
5 8
 /**
6 9
  * @author leon on 18/12/2018.
7 10
  */
8
-public class Group<_> {
11
+public class Group<_> extends LinkedList {
12
+
13
+    Group<_> group;
14
+
15
+
9 16
     public Group() {
17
+
18
+        group = new Group<_>();
19
+
20
+
10 21
         throw new UnsupportedOperationException("Method not yet implemented");
11 22
     }
12 23
 
13 24
     public Integer count() {
14
-        return null;
25
+        return group.size();
15 26
     }
16 27
 
17 28
     public void insert(_ value) {
29
+
30
+        group.add(value);
18 31
     }
19 32
 
20 33
     public Boolean has(_ value) {
21
-        return null;
34
+
35
+        if(group.contains(value)){
36
+            return true;
37
+        }
38
+
39
+        return false;
40
+
22 41
     }
23 42
 
24 43
     public _ fetch(int indexOfValue) {
25
-        return null;
44
+
45
+        _ test = (_) group.get(indexOfValue);
46
+
47
+        return test;
26 48
     }
27 49
 
28 50
     public void delete(_ value) {

+ 4
- 2
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java Целия файл

@@ -6,13 +6,15 @@ package rocks.zipcode.io.quiz4.generics;
6 6
 public class SortedGroup<_> extends Group<_> {
7 7
     @Override
8 8
     public void insert(_ value) {
9
+        group.insert(value);
9 10
     }
10 11
 
11 12
     @Override
12 13
     public void delete(_ value) {
13 14
     }
14 15
 
15
-    public Integer indexOf(_ firstValue) {
16
-        return null;
16
+
17
+    public int indexOf(Object firstValue) {
18
+        return 0;
17 19
     }
18 20
 }

+ 17
- 4
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java Целия файл

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

+ 24
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java Целия файл

@@ -1,17 +1,39 @@
1 1
 package rocks.zipcode.io.quiz4.objectorientation;
2 2
 
3
+import com.sun.deploy.util.StringUtils;
4
+import com.sun.tools.doclets.internal.toolkit.builders.AbstractBuilder;
5
+
6
+import java.util.ArrayList;
7
+import java.util.List;
8
+import java.util.StringJoiner;
9
+
3 10
 /**
4 11
  * @author leon on 11/12/2018.
5 12
  */
6 13
 public class StringAssembler {
14
+
15
+
16
+    StringBuilder builder = new StringBuilder();
17
+
18
+    Character delimeter;
19
+
7 20
     public StringAssembler(Character delimeter) {
21
+        this.delimeter = delimeter;
8 22
     }
9 23
 
10 24
     public StringAssembler append(String str) {
11
-        return null;
25
+
26
+        builder.append(str);
27
+        builder.append(delimeter.toString());
28
+
29
+        return this;
12 30
     }
13 31
 
14 32
     public String assemble() {
15
-        return null;
33
+
34
+        builder.deleteCharAt(builder.toString().length()-1);
35
+
36
+
37
+        return builder.toString();
16 38
     }
17 39
 }

+ 11
- 4
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java Целия файл

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

+ 14
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java Целия файл

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