Browse Source

pre-merge commit

Connor Dunnigan 5 years ago
parent
commit
30eee651df

+ 17
- 0
pom.xml View File

@@ -26,6 +26,23 @@
26 26
             <version>4.12</version>
27 27
             <scope>test</scope>
28 28
         </dependency>
29
+        <dependency>
30
+            <groupId>org.decimal4j</groupId>
31
+            <artifactId>decimal4j</artifactId>
32
+            <version>1.0.3</version>
33
+        </dependency>
34
+        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
35
+        <dependency>
36
+            <groupId>org.apache.commons</groupId>
37
+            <artifactId>commons-lang3</artifactId>
38
+            <version>3.0</version>
39
+        </dependency>
40
+        <dependency>
41
+            <groupId>org.reflections</groupId>
42
+            <artifactId>reflections</artifactId>
43
+            <version>0.9.11</version>
44
+        </dependency>
45
+
29 46
     </dependencies>
30 47
 
31 48
 

+ 11
- 4
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java View File

@@ -1,22 +1,29 @@
1 1
 package rocks.zipcode.quiz5.arrays;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+
3 6
 /**
4 7
  * @author leon on 01/01/2019.
5 8
  */
6 9
 public class ArrayUtils {
7 10
     public static String getMiddleElement(String[] values) {
8
-        return null;
11
+        return values[values.length/2];
9 12
     }
10 13
 
11 14
     public static String[] removeMiddleElement(String[] values) {
12
-        return null;
15
+        ArrayList<String> list = new ArrayList<>(Arrays.asList(values));
16
+        list.remove(values.length/2);
17
+        return list.toArray(new String[0]);
13 18
     }
14 19
 
15 20
     public static String getLastElement(String[] values) {
16
-        return null;
21
+        return values[values.length-1];
17 22
     }
18 23
 
19 24
     public static String[] removeLastElement(String[] values) {
20
-        return null;
25
+        ArrayList<String> list = new ArrayList<>(Arrays.asList(values));
26
+        list.remove(values.length-1);
27
+        return list.toArray(new String[0]);
21 28
     }
22 29
 }

+ 12
- 4
src/main/java/rocks/zipcode/quiz5/collections/Food.java View File

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

+ 9
- 1
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java View File

@@ -1,12 +1,20 @@
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
+    Map<String, Integer> wordCount;
6 8
     public WordCounter(String... strings) {
9
+        wordCount = new HashMap<>();
10
+        for(String str : strings)
11
+            if(wordCount.containsKey(str))
12
+                wordCount.put(str,wordCount.get(str) + 1);
13
+            else
14
+                wordCount.put(str,1);
7 15
     }
8 16
 
9 17
     public Map<String, Integer> getWordCountMap() {
10
-        return null;
18
+        return wordCount;
11 19
     }
12 20
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java View File

@@ -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 View File

@@ -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 View File

@@ -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
 }

+ 4
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java View File

@@ -3,11 +3,13 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 30/12/2018.
5 5
  */
6
-public class Account extends BankAccount {
6
+public class Account  {
7
+    private Long id;
7 8
     public Long getId() {
8
-        return null;
9
+        return id;
9 10
     }
10 11
 
11 12
     public void setId(Long id) {
13
+        this.id = id;
12 14
     }
13 15
 }

+ 22
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java View File

@@ -3,7 +3,28 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class BankAccount {
6
+public class BankAccount extends Account implements Transactable{
7
+    private Double balance;
7 8
     public void setBalance(Double val) {
9
+        balance = val;
10
+    }
11
+
12
+    @Override
13
+    public void deposit(Double amountToIncreaseBy) {
14
+        if(amountToIncreaseBy < 0)
15
+            throw new IllegalArgumentException();
16
+        balance += amountToIncreaseBy;
17
+    }
18
+
19
+    @Override
20
+    public void withdrawal(Double amountToDecreaseBy) {
21
+        if(amountToDecreaseBy > balance || amountToDecreaseBy < 0)
22
+            throw new IllegalArgumentException();
23
+        balance -= amountToDecreaseBy;
24
+    }
25
+
26
+    @Override
27
+    public Double getBalance() {
28
+        return balance;
8 29
     }
9 30
 }

+ 33
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java View File

@@ -3,18 +3,49 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 30/12/2018.
5 5
  */
6
-public class Employee {
6
+public class Employee implements Worker{
7
+    Double hourlyWage;
8
+    Double hoursWorked;
9
+    Double balance;
10
+    BankAccount bankAccount;
11
+
7 12
     public Employee() {
13
+         hourlyWage = 35.0;
14
+         hoursWorked = 0.0;
15
+         balance = 0.0;
16
+         bankAccount.setBalance(0.0);
8 17
     }
9 18
 
10 19
     public Employee(BankAccount bankAccount) {
20
+        this();
21
+        this.bankAccount = bankAccount;
11 22
     }
12 23
 
13 24
     public BankAccount getBankAccount() {
14
-        return null;
25
+        return bankAccount;
15 26
     }
16 27
 
17 28
     public void setBankAccount(BankAccount bankAccount) {
29
+        this.bankAccount = bankAccount;
30
+    }
31
+
32
+    @Override
33
+    public void increaseHoursWorked(Double numberOfHours) {
34
+        hoursWorked += numberOfHours;
35
+    }
36
+
37
+    @Override
38
+    public Double getHoursWorked() {
39
+        return hoursWorked;
40
+    }
41
+
42
+    @Override
43
+    public Double getHourlyWage() {
44
+        return hourlyWage;
45
+    }
18 46
 
47
+    @Override
48
+    public Double getMoneyEarned() {
49
+        return hourlyWage * hoursWorked;
19 50
     }
20 51
 }