Nathan Hall преди 6 години
родител
ревизия
f41d81743a

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

@@ -1,18 +1,28 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import java.util.Set;
4
+import java.util.TreeSet;
5
+
3 6
 /**
4 7
  * @author leon on 11/12/2018.
5 8
  */
6 9
 public class ComparableTreeSet<_> {
10
+
11
+
7 12
     public ComparableTreeSet(_... arr) {
8 13
 
14
+
9 15
     }
10 16
 
11 17
 
12 18
     public ComparableTreeSet() {
19
+
20
+        Set<_> set = new TreeSet<>();
13 21
     }
14 22
 
15 23
     public Integer compareTo(ComparableTreeSet<_> o) {
24
+
25
+
16 26
         return null;
17 27
     }
18 28
 }

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

@@ -2,22 +2,30 @@ package rocks.zipcode.io.quiz4.collections;
2 2
 
3 3
 import rocks.zipcode.io.quiz4.objectorientation.Student;
4 4
 
5
+import java.util.ArrayList;
6
+import java.util.HashMap;
5 7
 import java.util.Map;
6 8
 
7 9
 /**
8 10
  * @author leon on 11/12/2018.
9 11
  */
10 12
 public class ZipCodeWilmington {
11
-    private Student student;
13
+    private ArrayList<Student> students;
12 14
     private double numberOfHours;
15
+    private Student student;
13 16
 
14 17
     public void enroll(Student student) {
15
-        this.student = student;
18
+        students.add(student);
16 19
     }
17 20
 
18 21
     public Boolean isEnrolled(Student student) {
19 22
 
20
-        return null;
23
+        if (students.contains(student)){
24
+            return true;
25
+        }
26
+
27
+
28
+        return false;
21 29
     }
22 30
 
23 31
     public void lecture(double numberOfHours) {
@@ -25,7 +33,28 @@ public class ZipCodeWilmington {
25 33
     }
26 34
 
27 35
     public Map<Student, Double> getStudyMap() {
36
+        Map<Student, Double> map = new HashMap<>();
37
+
28 38
 
29 39
         return null;
30 40
     }
41
+
42
+
43
+
44
+
45
+    public Student getStudent() {
46
+        return student;
47
+    }
48
+
49
+    public void setStudent(Student student) {
50
+        this.student = student;
51
+    }
52
+
53
+    public double getNumberOfHours() {
54
+        return numberOfHours;
55
+    }
56
+
57
+    public void setNumberOfHours(double numberOfHours) {
58
+        this.numberOfHours = numberOfHours;
59
+    }
31 60
 }

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

@@ -4,18 +4,30 @@ package rocks.zipcode.io.quiz4.fundamentals;
4 4
 import com.sun.deploy.util.StringUtils;
5 5
 
6 6
 import java.util.ArrayList;
7
+import java.util.HashSet;
7 8
 import java.util.List;
9
+import java.util.Set;
8 10
 
9 11
 /**
10 12
  * @author leon on 18/12/2018.
11 13
  */
12 14
 public class PalindromeEvaluator {
13 15
     public static String[] getAllPalindromes(String string) {
14
-        char[] arr = string.toCharArray();
15
-        for (char c : arr){
16
-            System.out.println(c);
16
+        StringBuilder builder = new StringBuilder();
17
+        Set<String> set = new HashSet<>();
18
+        for (int i = 0; i < (string.length()/2) + 1; i++) {
19
+            if (string.charAt(string.length() - 1 - i) == string.charAt(i)){
20
+                builder.append(string.charAt(i) + ",");
21
+                builder.append(string.substring(i, string.length()-i) + ",");
22
+            }
23
+        }
24
+
25
+        String[] strSet = builder.toString().split(",");
26
+        for (String s : strSet){
27
+            set.add(s);
17 28
         }
18
-        return null;
29
+
30
+        return set.toArray(new String[0]);
19 31
     }
20 32
 
21 33
     public static Boolean isPalindrome(String string) {

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

@@ -1,13 +1,14 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
-import java.util.ArrayList;
4
-import java.util.List;
3
+import java.util.*;
5 4
 
6 5
 /**
7 6
  * @author leon on 11/12/2018.
8 7
  */
9 8
 public class StringEvaluator {
10 9
     public static String[] getAllPrefixes(String string) {
10
+        Set<String> set = new HashSet<>();
11
+
11 12
 
12 13
         StringBuilder builder = new StringBuilder();
13 14
         int index = 0;
@@ -15,16 +16,36 @@ public class StringEvaluator {
15 16
 
16 17
             for (int i = 0; i < string.length(); i++) {
17 18
                 builder.append(string.charAt(i) + ",");
18
-                for (int j = 1; j < string.length()-1; j++) {
19
-                    builder.append(string.substring(i) + ",");
19
+                builder.append(string.substring(i) + ",");
20
+                if (i < string.length()/2) {
21
+                    builder.append(string.substring(i, string.length() - 1) + ",");
20 22
                 }
21 23
             }
24
+            String[] arr = builder.toString().split(",");
22 25
 
23
-        return builder.toString().split(",");
26
+            for (String s : arr){
27
+                set.add(s);
28
+            }
29
+
30
+        return set.toArray(new String[0]);
24 31
     }
25 32
 
26 33
     public static String[] getCommonPrefixes(String string1, String string2) {
27
-        return null;
34
+            String[] str1 = getAllPrefixes(string1);
35
+            String[] str2 = getAllPrefixes(string2);
36
+            StringBuilder builder = new StringBuilder();
37
+
38
+
39
+        for (int i = 0; i < str2.length; i++) {
40
+            if (Arrays.asList(str1).contains(str2[i])){
41
+                builder.append(str2[i] + ",");
42
+            }
43
+        }
44
+
45
+
46
+
47
+
48
+        return builder.toString().split(",");
28 49
     }
29 50
 
30 51
     public static String getLargestCommonPrefix(String string1, String string2) {

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

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz4.objectorientation;
2 2
 
3
+import com.sun.tools.javac.util.StringUtils;
4
+
3 5
 /**
4 6
  * @author leon on 18/12/2018.
5 7
  */

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

@@ -4,10 +4,15 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 11/12/2018.
5 5
  */
6 6
 public class StringAssembler {
7
+    private Character delimeter;
8
+    private String str;
9
+
7 10
     public StringAssembler(Character delimeter) {
11
+        this.delimeter = delimeter;
8 12
     }
9 13
 
10 14
     public StringAssembler append(String str) {
15
+        this.str = str;
11 16
         return null;
12 17
     }
13 18