NiraParikh 6 年 前
コミット
a73dad42bd

+ 8
- 91
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java ファイルの表示

@@ -8,27 +8,16 @@ import java.util.List;
8 8
 /**
9 9
  * @author leon on 11/12/2018.
10 10
  */
11
-public class SimpleStringGroup implements Iterable, Collection {
12
-    private String string;
13
-    private String valueToInsert;
14
-    private int indexOfValue;
15
-
16
-
17
-    public SimpleStringGroup(String string, String valueToInsert, int indexOfValue) {
18
-        this.string = string;
19
-        this.valueToInsert = valueToInsert;
20
-        this.indexOfValue = indexOfValue;
21
-    }
11
+public class SimpleStringGroup implements Iterable {
22 12
 
23 13
     List<String> list = new ArrayList<>();
24
-    SimpleStringGroup group = new SimpleStringGroup();
25 14
 
26 15
     public SimpleStringGroup() {
27
-        throw new UnsupportedOperationException("Method not yet implemented");
16
+      //  throw new UnsupportedOperationException("Method not yet implemented");
28 17
     }
29 18
 
30 19
     public Integer count() {
31
-        return size();
20
+        return list.size();
32 21
     }
33 22
 
34 23
     public void insert(String string) {
@@ -43,94 +32,22 @@ public class SimpleStringGroup implements Iterable, Collection {
43 32
     }
44 33
 
45 34
     public String fetch(int indexOfValue) {
46
-      return String.valueOf(list.contains(indexOfValue));
47
-
35
+       return list.get(indexOfValue);
48 36
     }
49 37
 
50 38
     public void delete(String valueToInsert) {
51
-        group.delete(valueToInsert);
52
-    }
53
-
54
-    @Override
55
-    public int size() {
56
-        return size();
57
-    }
58
-
59
-    @Override
60
-    public boolean isEmpty() {
61
-
62
-      return list.isEmpty();
63
-    }
64
-
65
-    @Override
66
-    public boolean contains(Object o) {
67
-        if(list.equals(o)){
68
-            return true;
69
-        }
70
-        return false;
71
-    }
72
-
73
-    @Override
74
-    public Object[] toArray() {
75
-        return new Object[0];
76
-    }
77
-
78
-    @Override
79
-    public boolean add(Object o) {
80
-
81
-        return true;
82
-    }
83
-
84
-    @Override
85
-    public boolean remove(Object o) {
86
-        return group.remove(o);
87
-    }
88
-
89
-    @Override
90
-    public boolean addAll(Collection c) {
91
-        return group.addAll(c);
92
-    }
93
-
94
-    @Override
95
-    public boolean retainAll(Collection c) {
96
-        return group.retainAll(c);
97
-    }
98
-
99
-    @Override
100
-    public boolean removeAll(Collection c) {
101
-        return group.removeAll(c);
102
-    }
103
-
104
-    @Override
105
-    public boolean containsAll(Collection c) {
106
-        return group.containsAll(c);
107
-    }
108
-
109
-    @Override
110
-    public Object[] toArray(Object[] a) {
111
-        return new Object[0];
39
+        list.remove(valueToInsert);
112 40
     }
113 41
 
114 42
     public void clear() {
115
-        if (string.equals(valueToInsert)){
116
-            clear();
117
-        }
118
-
119
-    }
120
-
121
-    @Override
122
-    public String toString() {
123
-        return "SimpleStringGroup{" +
124
-                "string='" + string + '\'' +
125
-                ", valueToInsert='" + valueToInsert + '\'' +
126
-                ", indexOfValue=" + indexOfValue +
127
-                '}';
43
+        list.clear();
128 44
     }
129 45
 
130 46
     @Override
131 47
     public Iterator iterator() {
132
-        return null;
48
+        return list.iterator();
133 49
     }
134 50
 
135 51
 
52
+
136 53
 }

+ 9
- 4
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java ファイルの表示

@@ -9,20 +9,25 @@ import java.util.Map;
9 9
  */
10 10
 public class ZipCodeWilmington {
11 11
 
12
+    ZipCodeWilmington zipCodeWilmington = new ZipCodeWilmington();
13
+
12 14
     private Student student;
13 15
     private double numberOfHours;
14 16
 
15
-    public void enroll(Student student) {
17
+    public String enroll(Student student) {
16 18
         this.student = student;
19
+        return zipCodeWilmington.enroll(student);
17 20
     }
18 21
 
19 22
     public Boolean isEnrolled(Student student) {
20
-        this.student = student;
21
-        return null;
23
+       if(zipCodeWilmington.isEnrolled(student)){
24
+           return true;
25
+       }
26
+        return false;
22 27
     }
23 28
 
24 29
     public void lecture(double numberOfHours) {
25
-//        this.numberOfHours = numberOfHours;
30
+        this.numberOfHours = numberOfHours;
26 31
 //        double numOfHrsPerLearner = numberOfHours/student.length;
27 32
 //
28 33
 //        Student[] students;

+ 19
- 9
src/main/java/rocks/zipcode/io/quiz4/fundamentals/StringEvaluator.java ファイルの表示

@@ -2,6 +2,7 @@ package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3 3
 import com.sun.tools.javac.util.StringUtils;
4 4
 
5
+import java.lang.reflect.Array;
5 6
 import java.util.Arrays;
6 7
 import java.util.regex.Matcher;
7 8
 import java.util.regex.Pattern;
@@ -27,17 +28,26 @@ public class StringEvaluator {
27 28
     }
28 29
 
29 30
     public static String[] getCommonPrefixes(String string1, String string2) {
30
-        int i = 0;
31
-        
32
-        if (string1 == null || string2 == null || string1.length() == 0 || string2.length() == 0) {
33
-            return new String[]{""};
34
-        }
35
-
36
-        while (i < string1.length() && i < string2.length() && string1.charAt(i) == string2.charAt(i)) {
37
-            i++;
31
+        int minLength = Math.min(string1.length(), string2.length());
32
+        for (int i = 0; i < minLength; i++) {
33
+            if (string1.charAt(i) != string2.charAt(i)) {
34
+                return new String[]{string1.substring(0, i)};
35
+            }
38 36
         }
39
-        return new String[]{string1.substring(0, i)};
37
+        return new String[]{string1.substring(0, minLength)};
40 38
     }
39
+
40
+//        int i = 0;
41
+//
42
+//        if (string1 == null || string2 == null || string1.length() == 0 || string2.length() == 0) {
43
+//            return new String[]{""};
44
+//        }
45
+//
46
+//        while (i < string1.length() && i < string2.length() && string1.charAt(i) == string2.charAt(i)) {
47
+//            i++;
48
+//        }
49
+//        return new String[]{string1.substring(0, i)};
50
+//    }
41 51
     
42 52
 
43 53
     public static String getLargestCommonPrefix(String string1, String string2) {

+ 0
- 1
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java ファイルの表示

@@ -9,7 +9,6 @@ import java.util.TreeSet;
9 9
  */
10 10
 public class GenericUtils {
11 11
     private static Set<? extends Comparable> originalSet;
12
-//    private static Set<? extends Comparable> originalSet;
13 12
 
14 13
     public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
15 14
         GenericUtils.originalSet = originalSet;

+ 7
- 1
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java ファイルの表示

@@ -40,13 +40,19 @@ public class Group<_>{
40 40
     }
41 41
 
42 42
     public Iterator<_> iterator() {
43
-       List<_> rator = new ArrayList<>();
43
+       List<_> list = new ArrayList<>();
44 44
        Iterator<_> iterator = list.iterator();
45 45
         return iterator;
46
+//       return list.iterator();
46 47
     }
47 48
 
48 49
     public boolean has(_ valueToInsert) {
49 50
         return list.contains(valueToInsert);
50 51
     }
51 52
 
53
+    @Override
54
+    public String toString() {
55
+        return "" +
56
+                list;
57
+    }
52 58
 }

+ 3
- 6
src/main/java/rocks/zipcode/io/quiz4/generics/MyStack.java ファイルの表示

@@ -10,8 +10,6 @@ import java.util.Stack;
10 10
 public class MyStack<SomeType> implements Iterable {
11 11
     Stack<SomeType> stack = new Stack<>();
12 12
 
13
-//    private SomeType i;
14
-
15 13
     public MyStack() {
16 14
 
17 15
 //        throw new UnsupportedOperationException("Method not yet implemented");
@@ -27,14 +25,13 @@ public class MyStack<SomeType> implements Iterable {
27 25
         return stack.empty();
28 26
     }
29 27
 
30
-    public void push(SomeType elementsToBePushed) {
31
-        stack.push(elementsToBePushed);
32
-
28
+    public void push(SomeType i) {
29
+        stack.push(i);
33 30
     }
34 31
 
35 32
     public SomeType peek() {
36
-        return stack.peek();
37 33
 //        throw new UnsupportedOperationException("Method not yet implemented");
34
+        return stack.peek();
38 35
     }
39 36
 
40 37
     public SomeType pop() {

+ 11
- 1
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 java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 18/12/2018.
5 7
  */
@@ -12,8 +14,16 @@ public class PalindromeObject {
12 14
     }
13 15
 
14 16
     public String[] getAllPalindromes(){
15
-        return null;
16 17
 
18
+//        String ab = input.replaceAll("[^A-Za-z0-9]", "").toLowerCase();
19
+//        //System.out.println(ab);
20
+//
21
+//        for (int i=0; i<ab.length()/2; i++) {
22
+//            if(ab.charAt(i) != ab.charAt((ab.length()-1)-i)) {
23
+//                return input;
24
+//            }
25
+//        }
26
+        return null;
17 27
     }
18 28
 
19 29
     public Boolean isPalindrome(){

+ 8
- 6
src/main/java/rocks/zipcode/io/quiz4/objectorientation/StringAssembler.java ファイルの表示

@@ -14,18 +14,20 @@ public class StringAssembler {
14 14
     }
15 15
 
16 16
     public StringAssembler append(String str) {
17
+
17 18
         StringBuilder sb = new StringBuilder();
18 19
 
19
-        String loopDel = " ";
20
+        String[] temp = str.substring(0, str.length() -1).split(" ");
20 21
 
21 22
         for (int i = 0; i < str.length(); i++) {
22 23
 
23
-            sb.append(i);
24
-            sb.append(str);
25
-
26
-            loopDel = str;
27
-            System.out.println(loopDel);
24
+            sb.append(" \' \' " + str.substring(1));
25
+//            sb.append(" \n "  + str.substring(i));
26
+//            sb.append("_" + str.substring(i));
27
+//            sb.append(" ;"  +  str.substring(i));
28 28
         }
29
+
30
+        System.out.println(sb);
29 31
         return null;
30 32
     }
31 33
 

+ 8
- 5
src/main/java/rocks/zipcode/io/quiz4/objectorientation/Student.java ファイルの表示

@@ -5,13 +5,16 @@ import rocks.zipcode.io.quiz4.collections.ZipCodeWilmington;
5 5
 /**
6 6
  * @author leon on 11/12/2018.
7 7
  */
8
-public class Student extends ZipCodeWilmington {
8
+public class Student {
9 9
 
10 10
     private Integer id;
11
-    private Double amountOfHours;
11
+    private Double totalStudyTime = 0.0;
12
+    private  Double amountOfHours;
12 13
 
13 14
 
14
-    public Student(){}
15
+    public Student(){
16
+        this(null);
17
+    }
15 18
 
16 19
     public Student(Integer id) {
17 20
         this.id = id;
@@ -40,12 +43,12 @@ public class Student extends ZipCodeWilmington {
40 43
 
41 44
 
42 45
     public void learn(Double amountOfHours) {
43
-        this.amountOfHours = amountOfHours;
46
+        totalStudyTime += amountOfHours;
44 47
     }
45 48
 
46 49
     public Double getTotalStudyTime() {
47 50
 
48
-        return null;
51
+        return totalStudyTime;
49 52
     }
50 53
 
51 54
 }