Browse Source

pre-merge commit

Chaitali Patel 6 years ago
parent
commit
ec40925335

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

@@ -11,21 +11,18 @@ public class SimpleStringGroup {
11 11
         throw new UnsupportedOperationException("Method not yet implemented");
12 12
     }
13 13
 
14
-    Set<String> str = new HashSet<String>();
14
+    Set<String> set = new HashSet<String>();
15 15
 
16 16
     public Integer count() {
17
-        return str.size();
17
+        return set.size();
18 18
     }
19 19
 
20 20
     public void insert(String string) {
21
-        str.add(string);
21
+        set.add(string);
22 22
     }
23 23
 
24 24
     public Boolean has(String valueToInsert) {
25
-        if (str.contains(valueToInsert)){
26
-            return true;
27
-        }
28
-        return false;
25
+        return set.contains(valueToInsert);
29 26
     }
30 27
 
31 28
     public String fetch(int indexOfValue) {
@@ -33,10 +30,10 @@ public class SimpleStringGroup {
33 30
     }
34 31
 
35 32
     public void delete(String valueToInsert) {
36
-        str.remove(valueToInsert);
33
+        set.remove(valueToInsert);
37 34
     }
38 35
 
39 36
     public void clear() {
40
-        str.clear();
37
+        set.clear();
41 38
     }
42 39
 }

+ 2
- 6
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java View File

@@ -4,21 +4,17 @@ import rocks.zipcode.io.quiz4.objectorientation.Student;
4 4
 
5 5
 import java.util.HashMap;
6 6
 import java.util.Map;
7
-
8 7
 /**
9 8
  * @author leon on 11/12/2018.
10 9
  */
11 10
 public class ZipCodeWilmington {
12 11
     Map<Student, Double> stud = new HashMap<>();
13 12
     public void enroll(Student student) {
14
-        stud.size();
13
+        stud.put(student,1.0);
15 14
     }
16 15
 
17 16
     public Boolean isEnrolled(Student student) {
18
-        if (student != null) {
19
-            return true;
20
-        }
21
-        return false;
17
+        return student != null;
22 18
     }
23 19
 
24 20
     public void lecture(double numberOfHours) {

+ 5
- 6
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java View File

@@ -1,6 +1,5 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
-import java.util.Map;
4 3
 import java.util.TreeMap;
5 4
 
6 5
 /**
@@ -53,12 +52,12 @@ public class PalindromeEvaluator {
53 52
         }
54 53
         // printing all distinct palindromes from
55 54
         // hash map
56
-        for (Map.Entry<String, Integer> ii : m.entrySet()) {
57
-            System.out.println(ii.getKey());
58
-        }
59
-    return new String[]{m.toString()};
55
+//        for (Map.Entry<String, Integer> ii : m.entrySet()) {
56
+//            System.out.println(ii.getKey());
57
+//        }
58
+       return new String[]{m.toString()};
60 59
 
61
- }
60
+    }
62 61
 
63 62
     public static Boolean isPalindrome(String string) {
64 63
         int n = string.length();

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

@@ -1,5 +1,4 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2
-
3 2
 /**
4 3
  * @author leon on 11/12/2018.
5 4
  */
@@ -11,6 +10,7 @@ public class StringEvaluator {
11 10
             output[index] = "" + string ;
12 11
         }
13 12
         return output;
13
+
14 14
     }
15 15
 
16 16
     public static String[] getCommonPrefixes(String string1, String string2) {

+ 17
- 7
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java View File

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

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

@@ -10,11 +10,9 @@ public class MyStack<SomeType> {
10 10
         throw new UnsupportedOperationException("Method not yet implemented");
11 11
     }
12 12
 
13
-    Stack<SomeType> stack = new Stack<>();
13
+    private SomeType[] array;
14 14
 
15
-    public MyStack(Stack<SomeType> stack) {
16
-        this.stack = stack;
17
-    }
15
+    Stack stack = new Stack();
18 16
 
19 17
     public Boolean isEmpty() {
20 18
         return stack.isEmpty();
@@ -31,6 +29,7 @@ public class MyStack<SomeType> {
31 29
     }
32 30
 
33 31
     public SomeType pop() {
34
-        return stack.pop();
32
+        //return stack.pop();
33
+        return null;
35 34
     }
36 35
 }

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

@@ -3,16 +3,16 @@ package rocks.zipcode.io.quiz4.generics;
3 3
 /**
4 4
  * @author leon on 18/12/2018.
5 5
  */
6
-public class SortedGroup<_> extends Group<_> {
6
+public class SortedGroup<T> extends Group<T> {
7 7
     @Override
8
-    public void insert(_ value) {
8
+    public void insert(T value) {
9 9
     }
10 10
 
11 11
     @Override
12
-    public void delete(_ value) {
12
+    public void delete(T value) {
13 13
     }
14 14
 
15
-    public Integer indexOf(_ firstValue) {
15
+    public Integer indexOf(T firstValue) {
16 16
         return null;
17 17
     }
18 18
 }

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

@@ -4,7 +4,14 @@ package rocks.zipcode.io.quiz4.objectorientation;
4 4
  * @author leon on 18/12/2018.
5 5
  */
6 6
 public class PalindromeObject {
7
+    private String input;
8
+
9
+    public String getInput() {
10
+        return input;
11
+    }
12
+
7 13
     public PalindromeObject(String input) {
14
+        this.input = input;
8 15
     }
9 16
 
10 17
     public String[] getAllPalindromes(){
@@ -12,14 +19,17 @@ public class PalindromeObject {
12 19
     }
13 20
 
14 21
     public Boolean isPalindrome(){
15
-//        if () {
16
-//            return true;
17
-//        }
18
-        return false;
22
+        int n = input.length();
23
+        for (int i = 0; i < (n/2); ++i) {
24
+            if (input.charAt(i) != input.charAt(n - i - 1)) {
25
+                return false;
26
+            }
27
+        }
28
+
29
+        return true;
19 30
     }
20 31
 
21 32
     public String reverseString(){
22
-        String input = " ";
23 33
         StringBuilder str = new StringBuilder();
24 34
         str.append(input);
25 35
         str = str.reverse();