Procházet zdrojové kódy

made more than 150 test pass

Whitney Martinez před 6 roky
rodič
revize
419722c713

+ 44
- 5
src/main/java/rocks/zipcode/io/quiz4/collections/ComparableTreeSet.java Zobrazit soubor

@@ -1,17 +1,56 @@
1 1
 package rocks.zipcode.io.quiz4.collections;
2 2
 
3
+import java.util.Map;
4
+import java.util.SortedSet;
5
+import java.util.TreeSet;
6
+
3 7
 /**
4 8
  * @author leon on 11/12/2018dd.
5 9
  */
6
-public class ComparableTreeSet<_> {
7
-    public ComparableTreeSet(_... arr) {
10
+public class ComparableTreeSet<T> extends TreeSet implements Comparable {
11
+
12
+    private int id;
13
+    private String name;
14
+    private TreeSet<T> customSet = new TreeSet<>();
15
+
16
+    public ComparableTreeSet(T... arr) {
17
+
18
+        for (T x: arr) {
19
+            customSet.add(x);
20
+        }
21
+
22
+
23
+    }
24
+
25
+
26
+    public ComparableTreeSet(int id,String name) {
27
+        this.id = id;
28
+        this.name = name;
29
+
8 30
     }
9 31
 
32
+    public Integer compareTo(ComparableTreeSet<T> o) {
33
+
34
+        if(this.id > o.id ){
35
+
36
+            return 1;
37
+
38
+        }else if(this.id<o.id){
39
+
40
+            return -1;
41
+
42
+        }else{
43
+            return 0;
44
+        }
45
+    }
10 46
 
11
-    public ComparableTreeSet() {
47
+    @Override
48
+    public String toString() {
49
+        return customSet.toString() ;
12 50
     }
13 51
 
14
-    public Integer compareTo(ComparableTreeSet<_> o) {
15
-        return null;
52
+    @Override
53
+    public int compareTo(Object o) {
54
+        return 0;
16 55
     }
17 56
 }

+ 30
- 6
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java Zobrazit soubor

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

+ 23
- 3
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java Zobrazit soubor

@@ -2,23 +2,43 @@ 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 10
 public class ZipCodeWilmington {
11
+    private List<Student> students = new LinkedList<>();
12
+    HashMap<Student,Double> maps;
13
+
14
+
11 15
     public void enroll(Student student) {
16
+        students.add(student);
17
+
18
+
19
+
12 20
     }
13 21
 
14 22
     public Boolean isEnrolled(Student student) {
15
-        return null;
23
+
24
+        return students.contains(student);
25
+
16 26
     }
17 27
 
18 28
     public void lecture(double numberOfHours) {
29
+        for (Student x: students) {
30
+            x.learn(numberOfHours);
31
+            maps.put(x,x.getTotalStudyTime());
32
+            System.out.println(x);
33
+        }
34
+
35
+
19 36
     }
20 37
 
21 38
     public Map<Student, Double> getStudyMap() {
22
-        return null;
39
+
40
+        maps.put(students.,student.getTotalStudyTime());
41
+
42
+        return maps;
23 43
     }
24 44
 }

+ 19
- 3
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java Zobrazit soubor

@@ -1,18 +1,34 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import rocks.zipcode.io.quiz4.objectorientation.PalindromeObject;
4
+
5
+import java.util.ArrayList;
6
+
3 7
 /**
4 8
  * @author leon on 18/12/2018.
5 9
  */
6 10
 public class PalindromeEvaluator {
7 11
     public static String[] getAllPalindromes(String string) {
8
-        return null;
12
+        PalindromeObject p = new PalindromeObject(string);
13
+        return p.getAllPalindromes();
9 14
     }
10 15
 
11 16
     public static Boolean isPalindrome(String string) {
12
-        return null;
17
+
18
+       if(reverseString(string).equals(string)){
19
+           return true;
20
+       }
21
+       return false;
13 22
     }
14 23
 
15 24
     public static String reverseString(String string) {
16
-        return null;
25
+        String [] stringarr = string.split(" ");
26
+        String str = "";
27
+
28
+        for (int i = string.length()-1; i >= 0; i--) {
29
+            str += string.charAt(i);
30
+
31
+        }
32
+        return str;
17 33
     }
18 34
 }

+ 21
- 2
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java Zobrazit soubor

@@ -1,15 +1,34 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
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 9
 public class StringEvaluator {
7 10
     public static String[] getAllPrefixes(String string) {
8
-        return null;
11
+        ArrayList<String> list = new ArrayList<>();
12
+        String start = "";
13
+
14
+
15
+
16
+        for (int i = 0; i < string.length() ; i++) {
17
+
18
+            list.add(start);
19
+        }
20
+            return list.toArray(new String[0]);
9 21
     }
10 22
 
11 23
     public static String[] getCommonPrefixes(String string1, String string2) {
12
-        return null;
24
+        String first = string1.substring(0,1);
25
+        String second= string2.substring(0,1);
26
+        List<String> listing = new ArrayList<>();
27
+        if(first.equals(second)){
28
+            listing.add(first);
29
+            listing.add(second);
30
+        }
31
+        return listing.toArray(new String[0]);
13 32
     }
14 33
 
15 34
     public static String getLargestCommonPrefix(String string1, String string2) {

+ 7
- 4
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java Zobrazit soubor

@@ -1,15 +1,18 @@
1 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.util.*;
6 4
 
7 5
 /**
8 6
  * @author leon on 11/12/2018.
9 7
  */
10 8
 public class GenericUtils {
11 9
     public static <_ extends Comparable> Iterable<? extends Iterable<_>> powerSet(Set<_> originalSet) {
12
-        return null;
10
+        List<Set<_>> listing = new ArrayList<>();
11
+
12
+        listing.add(originalSet);
13
+
14
+        return listing;
15
+
13 16
     }
14 17
 
15 18
     public static <_ extends Comparable> Iterable<? extends Iterable<_>> powerSet(_... originalSet) {

+ 37
- 10
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java Zobrazit soubor

@@ -1,37 +1,64 @@
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 GroupInterface {
11
+
12
+     List<_> mygroup = new ArrayList<>();
9 13
     public Group() {
10
-        throw new UnsupportedOperationException("Method not yet implemented");
14
+
11 15
     }
12 16
 
13 17
     public Integer count() {
14
-        return null;
15
-    }
16 18
 
17
-    public void insert(_ value) {
19
+        return mygroup.size();
20
+
18 21
     }
19 22
 
20
-    public Boolean has(_ value) {
21
-        return null;
23
+    @Override
24
+    public Boolean has(Object valueToInsert) {
25
+        return mygroup.contains(valueToInsert);
22 26
     }
23 27
 
28
+
29
+
30
+
31
+
24 32
     public _ fetch(int indexOfValue) {
25
-        return null;
33
+        return mygroup.get(indexOfValue);
34
+    }
35
+
36
+    @Override
37
+    public void insert(Object string) {
38
+        mygroup.add((_)string);
39
+
26 40
     }
27 41
 
28
-    public void delete(_ value) {
42
+    @Override
43
+    public void delete(Object valueToInsert) {
44
+        mygroup.remove(valueToInsert);
45
+
46
+
29 47
     }
30 48
 
49
+
50
+
31 51
     public void clear() {
52
+
53
+        mygroup.clear();
32 54
     }
33 55
 
34 56
     public Iterator<_> iterator() {
35
-        return null;
57
+        return mygroup.iterator();
58
+    }
59
+
60
+    @Override
61
+    public String toString() {
62
+        return mygroup.toString();
36 63
     }
37 64
 }

+ 26
- 5
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java Zobrazit soubor

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

+ 14
- 3
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java Zobrazit soubor

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

+ 58
- 6
src/main/java/rocks/zipcode/io/quiz4/objectorientation/PalindromeObject.java Zobrazit soubor

@@ -1,21 +1,73 @@
1 1
 package rocks.zipcode.io.quiz4.objectorientation;
2 2
 
3
+import rocks.zipcode.io.quiz4.fundamentals.PalindromeEvaluator;
4
+
5
+import java.util.*;
6
+
3 7
 /**
4 8
  * @author leon on 18/12/2018.
5 9
  */
6 10
 public class PalindromeObject {
11
+
12
+    String input = "";
13
+
14
+
7 15
     public PalindromeObject(String input) {
16
+        this.input = input;
8 17
     }
9 18
 
10
-    public String[] getAllPalindromes(){
11
-        return null;
12
-    }
19
+    public String[] getAllPalindromes() {
20
+        List<String> list = new ArrayList<String>();
21
+
22
+
23
+        for(float pivot = 0; pivot < input.length(); pivot += .5){
24
+
25
+            float palindromeRadius = pivot - (int) pivot;
26
+
27
+            while ((pivot + palindromeRadius)<input.length()&&(pivot - palindromeRadius) >= 0
28
+                    && input.charAt((int)(pivot - palindromeRadius))
29
+                    == input.charAt((int)(pivot + palindromeRadius))){
30
+
31
+                list.add(input.substring((int)(pivot - palindromeRadius),
32
+                        (int)(pivot + palindromeRadius + 1)));
33
+
34
+                palindromeRadius++;
35
+            }
36
+        }
37
+        Set<String> d  = new HashSet<String>(list);
38
+
39
+        return d.toArray(new String[0]);
40
+
41
+}
13 42
 
14 43
     public Boolean isPalindrome(){
15
-        return null;
44
+        if(reverseString().equals(input)){
45
+            return true;
46
+        }
47
+        return false;
16 48
     }
17 49
 
18
-    public String reverseString(){
19
-        return null;
50
+    public String reverseString() {
51
+
52
+        StringBuffer sb = new StringBuffer();
53
+        String str2 = "";
54
+        String in = input.toLowerCase();
55
+        String str = in.substring(0,1).toUpperCase();
56
+
57
+        if(input.substring(0,1).equals(in.substring(0,1))){
58
+
59
+            sb.append(input);
60
+            sb.reverse();
61
+            str2 = sb.toString();
62
+
63
+        }else{
64
+            PalindromeEvaluator.reverseString(str);
65
+            str2 = str + in.substring(1);
66
+
67
+        }
68
+        return str2;
69
+
70
+     //   String g = str.substring(0,1).toUpperCase() + str.substring(1);
71
+
20 72
     }
21 73
 }

+ 32
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java Zobrazit soubor

@@ -4,14 +4,44 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 11/12/2018.
5 5
  */
6 6
 public class StringAssembler {
7
+    Character ch;
8
+    String str;
9
+
7 10
     public StringAssembler(Character delimeter) {
11
+
12
+        this.ch = delimeter;
13
+
14
+
8 15
     }
9 16
 
10 17
     public StringAssembler append(String str) {
11
-        return null;
18
+        StringAssembler sA = new StringAssembler(ch);
19
+        String[] split = str.split(" ");
20
+        String x = "";
21
+        StringBuffer sb = new StringBuffer();
22
+
23
+        for (int i = 0; i < str.length() ; i++) {
24
+
25
+
26
+
27
+            sb.append(split[i]);
28
+            sb.append(ch);
29
+
30
+        }
31
+
32
+        x = sb.toString();
33
+
34
+
35
+        return sA;
36
+
12 37
     }
13 38
 
14 39
     public String assemble() {
15
-        return null;
40
+
41
+
42
+
43
+
44
+       return null;
45
+
16 46
     }
17 47
 }

+ 11
- 2
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java Zobrazit soubor

@@ -4,17 +4,26 @@ 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 studytime;
9
+
7 10
     public Student() {
8
-        this(null);
11
+       this.studytime = 0.0;
12
+
9 13
     }
10 14
 
11 15
     public Student(Integer id) {
16
+        this.id = id;
12 17
     }
13 18
 
19
+
14 20
     public void learn(Double amountOfHours) {
21
+
22
+        this.studytime += amountOfHours;
23
+
15 24
     }
16 25
 
17 26
     public Double getTotalStudyTime() {
18
-        return null;
27
+        return studytime;
19 28
     }
20 29
 }