Saurav Kamath преди 5 години
родител
ревизия
35de62a378

+ 16
- 4
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java Целия файл

@@ -5,18 +5,30 @@ package rocks.zipcode.quiz5.arrays;
5 5
  */
6 6
 public class ArrayUtils {
7 7
     public static String getMiddleElement(String[] values) {
8
-        return null;
8
+        return values[values.length/2];
9 9
     }
10 10
 
11 11
     public static String[] removeMiddleElement(String[] values) {
12
-        return null;
12
+        String remove = getMiddleElement(values);
13
+        String[] fin = new String[values.length-1];
14
+        for(int i = 0; i < values.length/2; i++){
15
+            fin[i] = values[i];
16
+        }
17
+        for(int i = (values.length/2); i < fin.length; i++){
18
+            fin[i] = values[i+1];
19
+        }
20
+        return fin;
13 21
     }
14 22
 
15 23
     public static String getLastElement(String[] values) {
16
-        return null;
24
+        return values[values.length-1];
17 25
     }
18 26
 
19 27
     public static String[] removeLastElement(String[] values) {
20
-        return null;
28
+        String[] fin = new String[values.length-1];
29
+        for(int i = 0; i < fin.length; i++){
30
+            fin[i] = values[i];
31
+        }
32
+        return fin;
21 33
     }
22 34
 }

+ 12
- 3
src/main/java/rocks/zipcode/quiz5/collections/Bank.java Целия файл

@@ -2,18 +2,27 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.account.BankAccount;
4 4
 
5
+import java.util.*;
6
+
5 7
 /**
6 8
  * @author leon on 27/12/2018.
7 9
  */
8
-public class Bank {
10
+public class Bank extends HashMap{
11
+    private Map <Integer, BankAccount> BankAccounts = new HashMap<>();
12
+
9 13
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
10
-        return null;
14
+        BankAccounts.remove(indexNumber);
15
+        return BankAccounts.get(indexNumber);
11 16
     }
12 17
 
13 18
     public void addBankAccount(BankAccount bankAccount) {
19
+        BankAccounts.put(BankAccounts.size(), bankAccount);
14 20
     }
15 21
 
16 22
     public Boolean containsBankAccount(BankAccount bankAccount) {
17
-        throw new UnsupportedOperationException("Method not yet implemented");
23
+        if(BankAccounts.containsValue(bankAccount)){
24
+            return true;
25
+        }
26
+        return false;
18 27
     }
19 28
 }

+ 13
- 2
src/main/java/rocks/zipcode/quiz5/collections/Food.java Целия файл

@@ -2,15 +2,20 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.Spice;
4 4
 
5
+import java.util.ArrayList;
6
+import java.util.HashMap;
5 7
 import java.util.List;
6 8
 import java.util.Map;
7 9
 
8 10
 /**
9 11
  * @author leon on 27/12/2018.
10 12
  */
11
-public class Food {
13
+public class Food extends HashMap<Spice, Integer> {
14
+    Map<Spice, Integer> Spices = new HashMap<>();
15
+    ArrayList<Spice> SpiceList = new ArrayList<>();
16
+
12 17
     public List<Spice> getAllSpices() {
13
-        return null;
18
+        return SpiceList;
14 19
     }
15 20
 
16 21
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
@@ -18,5 +23,11 @@ public class Food {
18 23
     }
19 24
 
20 25
     public void applySpice(Spice spice) {
26
+        if(Spices.containsValue(spice)){
27
+            Spices.put(spice, Spices.get(spice)+1);
28
+        }else{
29
+            Spices.put(spice, 1);
30
+        }
31
+        SpiceList.add(spice);
21 32
     }
22 33
 }

+ 6
- 1
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Целия файл

@@ -1,9 +1,14 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
-import java.util.Map;
3
+import java.util.*;
4 4
 
5 5
 public class WordCounter {
6
+
7
+    Map<String, Integer> wordCounter= new HashMap<>();
8
+
6 9
     public WordCounter(String... strings) {
10
+
11
+
7 12
     }
8 13
 
9 14
     public Map<String, Integer> getWordCountMap() {

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java Целия файл

@@ -1,4 +1,4 @@
1 1
 package rocks.zipcode.quiz5.objectorientation;
2 2
 
3
-public class Curry {
3
+public class Curry implements Spice{
4 4
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Ginger.java Целия файл

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Ginger {
6
+public class Ginger implements Spice{
7 7
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Pepper.java Целия файл

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Pepper {
6
+public class Pepper implements Spice{
7 7
 }