Parcourir la source

testtteerrrrrssszzzzz

De'Jon Johnson il y a 6 ans
Parent
révision
c487024818

+ 17
- 5
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java Voir le fichier

@@ -10,16 +10,28 @@ public class PalindromeEvaluator {
10 10
 
11 11
 
12 12
     public static String[] getAllPalindromes(String string) {
13
-
14
-
15
-        return null;
13
+        List<String> result = new ArrayList<>();
14
+       for (int i = 0; i < string.length(); i++) {
15
+            for (int j = i + 1; j <= string.length(); j++) {
16
+                 if(isPalindrome(string.substring(i,j)) && !result.contains(string.substring(i,j))) {
17
+                    result.add(string.substring(i, j));
18
+                     }
19
+               }
20
+           }
21
+      return result.toArray(new String[0]);
16 22
     }
17 23
 
18 24
     public static Boolean isPalindrome(String string) {
19
-        return null;
25
+
26
+        return string.equals(reverseString(string));
20 27
     }
21 28
 
22 29
     public static String reverseString(String string) {
23
-        return null;
30
+
31
+        String newString = "";
32
+        for (int i = string.length() - 1; i >= 0 ; i--) {
33
+          newString += string.charAt(i);
34
+           }
35
+     return newString;
24 36
     }
25 37
 }

+ 25
- 4
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java Voir le fichier

@@ -1,21 +1,42 @@
1 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 8
  * @author leon on 11/12/2018.
5 9
  */
6 10
 public class StringEvaluator {
7 11
     public static String[] getAllPrefixes(String string) {
8 12
 
9
-        return null;
13
+        ArrayList<String> list = new ArrayList<>();
14
+       for (int i = 0; i < string.length(); i++) {
15
+             for (int j = string.length(); j > i; j--) {
16
+                 if (!list.contains(string.substring(i, j))) {
17
+                    list.add(string.substring(i, j));
18
+                     }
19
+              }
20
+           }
21
+       return list.toArray(new String[list.size()]);
10 22
     }
11 23
 
12 24
     public static String[] getCommonPrefixes(String string1, String string2) {
25
+        List<String> result = new ArrayList<String>(Arrays.asList(getAllPrefixes(string1)));
26
+       result.retainAll(Arrays.asList(getAllPrefixes(string2)));
27
+       return result.toArray(new String[0]);
28
+
13 29
 
14
-        return null;
15 30
     }
16 31
 
17 32
     public static String getLargestCommonPrefix(String string1, String string2) {
18
-
19
-        return null;
33
+        String[] newArray = getCommonPrefixes(string1,string2);
34
+        String str = "";
35
+         for (String s : newArray) {
36
+            if (s.length() > str.length()) {
37
+               str = s;
38
+                }
39
+           }
40
+      return str;
20 41
     }
21 42
 }

+ 14
- 6
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java Voir le fichier

@@ -1,37 +1,45 @@
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.List;
4 6
 
5 7
 /**
6 8
  * @author leon on 18/12/2018.
7 9
  */
8
-public class Group<_> {
10
+public class Group<_> implements Iterable<_>, GroupInterface<_> {
11
+    List<_> result = new ArrayList<>();
9 12
     public Group() {
10
-        throw new UnsupportedOperationException("Method not yet implemented");
13
+//        throw new UnsupportedOperationException("Method not yet implemented");
11 14
     }
12 15
 
16
+
13 17
     public Integer count() {
14
-        return null;
18
+        return result.size();
15 19
     }
16 20
 
17 21
     public void insert(_ value) {
22
+        result.add(value);
18 23
     }
19 24
 
20 25
     public Boolean has(_ value) {
21
-        return null;
26
+        return result.contains(value);
22 27
     }
23 28
 
24 29
     public _ fetch(int indexOfValue) {
25
-        return null;
30
+        return result.get(indexOfValue);
26 31
     }
27 32
 
28 33
     public void delete(_ value) {
34
+        result.remove(value);
29 35
     }
30 36
 
31 37
     public void clear() {
38
+        result.clear();
32 39
     }
33 40
 
34 41
     public Iterator<_> iterator() {
35
-        return null;
42
+        Iterator<_> list = result.iterator();
43
+        return list;
36 44
     }
37 45
 }

+ 23
- 3
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java Voir le fichier

@@ -1,21 +1,41 @@
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 11
 public class PalindromeObject {
12
+
13
+    private String input;
7 14
     public PalindromeObject(String input) {
15
+        this.input = input;
8 16
     }
9 17
 
10 18
     public String[] getAllPalindromes(){
11
-        return null;
19
+
20
+        Set<String> list = new HashSet<>();
21
+        for (int i = 0; i < this.input.length(); i++){
22
+            for (int j = i + 1; j <= this.input.length(); j++){
23
+               if(PalindromeEvaluator.isPalindrome(this.input.substring(i, j))){
24
+                    list.add(this.input.substring(i, j));
25
+                    }
26
+                }
27
+           }
28
+
29
+       return list.toArray(new String[0]);
12 30
     }
13 31
 
14 32
     public Boolean isPalindrome(){
15
-        return null;
33
+
34
+        return (reverseString().equals(this.input));
16 35
     }
17 36
 
18 37
     public String reverseString(){
19
-        return null;
38
+
39
+        return new StringBuilder(this.input).reverse().toString();
20 40
     }
21 41
 }

+ 10
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java Voir le fichier

@@ -4,14 +4,22 @@ 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 fixer;
9
+
7 10
     public StringAssembler(Character delimeter) {
11
+        this.delimeter = delimeter;
12
+         this.fixer = "";
8 13
     }
9 14
 
10 15
     public StringAssembler append(String str) {
11
-        return null;
16
+
17
+        fixer += str + delimeter;
18
+        return this;
12 19
     }
13 20
 
14 21
     public String assemble() {
15
-        return null;
22
+
23
+        return fixer.substring(0, fixer.length() -1);
16 24
     }
17 25
 }

+ 20
- 3
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringEvaluatorObject.java Voir le fichier

@@ -1,21 +1,38 @@
1 1
 package rocks.zipcode.io.quiz4.objectorientation;
2 2
 
3
+import rocks.zipcode.io.quiz4.fundamentals.StringEvaluator;
4
+
5
+import java.util.HashSet;
6
+import java.util.Set;
7
+
3 8
 /**
4 9
  * @author leon on 19/12/2018.
5 10
  */
6 11
 public class StringEvaluatorObject {
12
+    private String str;
13
+
7 14
     public StringEvaluatorObject(String str) {
15
+        this.str = str;
8 16
     }
9 17
 
10 18
     public String[] getAllPrefixes() {
11
-        return null;
19
+
20
+        Set<String> results = new HashSet<>();
21
+        for (int i = 0; i < str.length(); i++){
22
+             for (int j = i + 1; j <= str.length(); j++){
23
+                 results.add(str.substring(i, j));
24
+                }
25
+          }
26
+      return results.toArray(new String[0]);
12 27
     }
13 28
 
14 29
     public String[] getCommonPrefixes(String secondInput) {
15
-        return null;
30
+
31
+        return StringEvaluator.getCommonPrefixes(str, secondInput);
16 32
     }
17 33
 
18 34
     public String getLargestCommonPrefix(String secondInput) {
19
-        return null;
35
+
36
+        return StringEvaluator.getLargestCommonPrefix(str, secondInput);
20 37
     }
21 38
 }

+ 8
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java Voir le fichier

@@ -4,17 +4,23 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 11/12/2018.
5 5
  */
6 6
 public class Student {
7
+    private int id;
8
+    private double studyLength;
7 9
     public Student() {
8
-        this(null);
10
+
11
+        this(0);
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
+        studyLength += amountOfHours;
15 20
     }
16 21
 
17 22
     public Double getTotalStudyTime() {
18
-        return null;
23
+
24
+        return studyLength;
19 25
     }
20 26
 }