Selaa lähdekoodia

Got Collections.WordCounter

Nathan Hall 5 vuotta sitten
vanhempi
commit
609ddf2f05

+ 31
- 1
src/main/java/rocks/zipcode/quiz5/collections/Bank.java Näytä tiedosto

@@ -2,18 +2,48 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.account.BankAccount;
4 4
 
5
+import java.util.ArrayList;
6
+import java.util.List;
7
+
5 8
 /**
6 9
  * @author leon on 27/12/2018.
7 10
  */
8 11
 public class Bank {
12
+    private Integer indexNumber;
13
+    private List<BankAccount> bankAccounts;
14
+
15
+    public Bank() { this.bankAccounts = new ArrayList<>();
16
+    }
17
+
9 18
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
19
+        bankAccounts.remove(indexNumber);
20
+
10 21
         return null;
11 22
     }
12 23
 
13 24
     public void addBankAccount(BankAccount bankAccount) {
25
+        bankAccounts.add(bankAccount);
26
+
27
+
14 28
     }
15 29
 
16 30
     public Boolean containsBankAccount(BankAccount bankAccount) {
17
-        throw new UnsupportedOperationException("Method not yet implemented");
31
+
32
+        return bankAccounts.contains(bankAccount);
18 33
     }
34
+
35
+    public Integer getIndexNumber() {
36
+        return indexNumber;
37
+    }
38
+
39
+    public void setIndexNumber(Integer indexNumber) {
40
+        this.indexNumber = indexNumber;
41
+    }
42
+
43
+    public BankAccount getBankAccount(Integer indexNumber) {
44
+
45
+        return bankAccounts.get(indexNumber);
46
+    }
47
+
48
+
19 49
 }

+ 18
- 1
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Näytä tiedosto

@@ -1,12 +1,29 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
+import java.util.HashMap;
3 4
 import java.util.Map;
4 5
 
5 6
 public class WordCounter {
7
+    private String[] strings;
8
+
6 9
     public WordCounter(String... strings) {
10
+        this.strings = strings;
7 11
     }
8 12
 
9 13
     public Map<String, Integer> getWordCountMap() {
10
-        return null;
14
+        Map<String, Integer> map = new HashMap<>();
15
+        Integer holder = 0;
16
+
17
+        for (String s : strings){
18
+            if (map.containsKey(s)){
19
+                holder = map.get(s);
20
+                holder++;
21
+                map.put(s, holder);
22
+            } else {
23
+                map.put(s, 1);
24
+            }
25
+        }
26
+
27
+        return map;
11 28
     }
12 29
 }