Kaynağa Gözat

pre-merge commit

Kate Moore 6 yıl önce
ebeveyn
işleme
f545cdf1ec

+ 6
- 0
pom.xml Dosyayı Görüntüle

@@ -26,6 +26,12 @@
26 26
             <version>4.12</version>
27 27
             <scope>test</scope>
28 28
         </dependency>
29
+        <dependency>
30
+            <groupId>junit</groupId>
31
+            <artifactId>junit</artifactId>
32
+            <version>4.12</version>
33
+            <scope>test</scope>
34
+        </dependency>
29 35
     </dependencies>
30 36
 
31 37
 

+ 19
- 5
src/main/java/rocks/zipcode/io/quiz4/collections/SimpleStringGroup.java Dosyayı Görüntüle

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

+ 16
- 1
src/main/java/rocks/zipcode/io/quiz4/collections/ZipCodeWilmington.java Dosyayı Görüntüle

@@ -2,20 +2,35 @@ package rocks.zipcode.io.quiz4.collections;
2 2
 
3 3
 import rocks.zipcode.io.quiz4.objectorientation.Student;
4 4
 
5
+import java.util.HashMap;
5 6
 import java.util.Map;
6 7
 
7 8
 /**
8 9
  * @author leon on 11/12/2018.
9 10
  */
10 11
 public class ZipCodeWilmington {
12
+
13
+    private Map<Student, Double> students;
14
+    private Student student;
15
+
16
+    public ZipCodeWilmington() {
17
+        students = new HashMap<>();
18
+    }
19
+
20
+    public ZipCodeWilmington(Map<Student, Double> students) {
21
+        this.students = students;
22
+    }
23
+
11 24
     public void enroll(Student student) {
25
+        students.put(student, 0.0);
12 26
     }
13 27
 
14 28
     public Boolean isEnrolled(Student student) {
15
-        return null;
29
+        return students.containsKey(student);
16 30
     }
17 31
 
18 32
     public void lecture(double numberOfHours) {
33
+
19 34
     }
20 35
 
21 36
     public Map<Student, Double> getStudyMap() {

+ 3
- 1
src/main/java/rocks/zipcode/io/quiz4/fundamentals/PalindromeEvaluator.java Dosyayı Görüntüle

@@ -1,5 +1,7 @@
1 1
 package rocks.zipcode.io.quiz4.fundamentals;
2 2
 
3
+import java.util.ArrayList;
4
+
3 5
 /**
4 6
  * @author leon on 18/12/2018.
5 7
  */
@@ -9,7 +11,7 @@ public class PalindromeEvaluator {
9 11
     }
10 12
 
11 13
     public static Boolean isPalindrome(String string) {
12
-        for (int i = 0; i <string.length()/2; i++)
14
+        for (int i = 0; i <string.length()-1; i++)
13 15
             if(string.charAt(i)== string.charAt(string.length()-i)) {
14 16
                 return true;
15 17
             }

+ 4
- 3
src/main/java/rocks/zipcode/io/quiz4/generics/GenericUtils.java Dosyayı Görüntüle

@@ -1,6 +1,7 @@
1 1
 package rocks.zipcode.io.quiz4.generics;
2 2
 
3 3
 import java.util.Arrays;
4
+import java.util.HashSet;
4 5
 import java.util.Set;
5 6
 import java.util.TreeSet;
6 7
 
@@ -8,11 +9,11 @@ import java.util.TreeSet;
8 9
  * @author leon on 11/12/2018.
9 10
  */
10 11
 public class GenericUtils {
11
-    public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(Set<_> originalSet) {
12
+    public static <T extends Comparable> Iterable<Iterable<T>> powerSet(Set<T> originalSet) {
12 13
         return null;
13 14
     }
14 15
 
15
-    public static <_ extends Comparable> Iterable<Iterable<_>> powerSet(_... originalSet) {
16
+    public static <T extends Comparable> Iterable<Iterable<T>> powerSet(T... originalSet) {
16 17
         return powerSet(new TreeSet<>(Arrays.asList(originalSet)));
17
-    }
18
+   }
18 19
 }

+ 23
- 11
src/main/java/rocks/zipcode/io/quiz4/generics/Group.java Dosyayı Görüntüle

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

+ 5
- 5
src/main/java/rocks/zipcode/io/quiz4/generics/GroupInterface.java Dosyayı Görüntüle

@@ -3,11 +3,11 @@ package rocks.zipcode.io.quiz4.generics;
3 3
 /**
4 4
  * @author leon on 18/12/2018.
5 5
  */
6
-public interface GroupInterface<_> extends Iterable<_> {
6
+public interface GroupInterface<SomeType> extends Iterable<SomeType> {
7 7
     Integer count();
8
-    Boolean has(_ valueToInsert);
9
-    _ fetch(int indexOfValue);
10
-    void insert(_ string);
11
-    void delete(_ valueToInsert);
8
+    Boolean has(SomeType valueToInsert);
9
+    SomeType fetch(int indexOfValue);
10
+    void insert(SomeType string);
11
+    void delete(SomeType valueToInsert);
12 12
     void clear();
13 13
 }

+ 4
- 4
src/main/java/rocks/zipcode/io/quiz4/generics/SortedGroup.java Dosyayı Görüntüle

@@ -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<Type> extends Group<Type> {
7 7
     @Override
8
-    public void insert(_ value) {
8
+    public void insert(Type value) {
9 9
     }
10 10
 
11 11
     @Override
12
-    public void delete(_ value) {
12
+    public void delete(Type value) {
13 13
     }
14 14
 
15
-    public Integer indexOf(_ firstValue) {
15
+    public Integer indexOf(Type firstValue) {
16 16
         return null;
17 17
     }
18 18
 }