Browse Source

pre-merge commit

Elliott Stansbury 5 years ago
parent
commit
fe0b3fb410

+ 22
- 3
src/main/java/rocks/zipcode/quiz5/collections/Bank.java View File

@@ -2,18 +2,37 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.account.BankAccount;
4 4
 
5
+import java.util.ArrayList;
6
+
5 7
 /**
6 8
  * @author leon on 27/12/2018.
7 9
  */
8
-public class Bank {
10
+public class Bank extends ArrayList{
11
+
12
+    ArrayList<BankAccount> bank = new ArrayList<>();
13
+    BankAccount bankAccount = new BankAccount();
14
+
15
+
9 16
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
10
-        return null;
17
+
18
+        for(int i = 0; i < bank.size();i++){
19
+            if(i == indexNumber){
20
+                bank.remove(indexNumber);
21
+            }
22
+        }
23
+
24
+        return bankAccount;
11 25
     }
12 26
 
13 27
     public void addBankAccount(BankAccount bankAccount) {
28
+
29
+        bank.add(bankAccount);
14 30
     }
15 31
 
16 32
     public Boolean containsBankAccount(BankAccount bankAccount) {
17
-        throw new UnsupportedOperationException("Method not yet implemented");
33
+        if(bank.contains(bankAccount)){
34
+            return true;
35
+        }
36
+        return false;
18 37
     }
19 38
 }

+ 36
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java View File

@@ -1,35 +1,64 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
3 6
 /**
4 7
  * @author leon on 21/12/2018.
5 8
  */
6 9
 public class Calculator {
7 10
     public static Double squareRoot(Double value) {
8
-        return null;
11
+        return Math.sqrt(value);
9 12
     }
10 13
 
11 14
     public static Double square(Double value) {
12
-        return null;
15
+
16
+        Double sum = Math.pow(value,2);
17
+
18
+        String str = String.format("%1.5f", sum);
19
+        sum = Double.valueOf(str);
20
+        System.out.println(sum);
21
+
22
+        return sum;
13 23
     }
14 24
 
15 25
     public static Double[] squareRoots(Double... value) {
16
-        return null;
26
+
27
+        List<Double> list = new ArrayList<>();
28
+
29
+        for(Double v: value){
30
+            list.add(squareRoot(v));
31
+        }
32
+
33
+        return list.toArray(new Double[0]);
17 34
     }
18 35
 
19 36
     public static Double[] squares(Double... values) {
20
-        return null;
37
+        List<Double> list = new ArrayList<>();
38
+
39
+        for(Double v: values){
40
+            list.add(square(v));
41
+        }
42
+
43
+        return list.toArray(new Double[0]);
21 44
     }
22 45
 
23 46
     public static Double add(Double value1, Double value2) {
24
-        return null;
47
+
48
+        Double sum = value1 + value2;
49
+        String str = String.format("%1.2f", sum);
50
+        sum = Double.valueOf(str);
51
+        System.out.println(sum);
52
+
53
+        return sum;
25 54
     }
26 55
 
27 56
     public static Double subtract(Double value1, Double value2) {
28
-        return null;
57
+        return value1 - value2;
29 58
     }
30 59
 
31 60
 
32 61
     public static Double divide(Double divisor, Double dividend) {
33
-        return null;
62
+        return divisor/dividend;
34 63
     }
35 64
 }

+ 64
- 6
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java View File

@@ -1,31 +1,89 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 /**
4 6
  * @author leon on 21/12/2018.
5 7
  */
6 8
 public class StringUtils {
7 9
     public static Character getMiddleCharacter(String string) {
8
-        return null;
10
+
11
+        return string.charAt(string.length()/2);
9 12
     }
10 13
 
11 14
     public static String capitalizeMiddleCharacter(String str) {
12
-        return null;
15
+
16
+        String[] letters = str.split("");
17
+        StringBuilder builder = new StringBuilder();
18
+
19
+        for(int i =0; i < letters.length; i++){
20
+            if(i == letters.length/2){
21
+                builder.append(letters[i].toUpperCase());
22
+            }else {
23
+                builder.append(letters[i]);
24
+            }
25
+            }
26
+
27
+        return builder.toString();
13 28
     }
14 29
 
15 30
     public static String lowerCaseMiddleCharacter(String str) {
16
-        return null;
31
+
32
+        String[] letters = str.split("");
33
+        StringBuilder builder = new StringBuilder();
34
+
35
+        for(int i =0; i < letters.length; i++){
36
+            if(i == letters.length/2){
37
+                builder.append(letters[i].toLowerCase());
38
+            }else {
39
+                builder.append(letters[i]);
40
+            }
41
+        }
42
+
43
+        return builder.toString();
17 44
     }
18 45
 
19 46
     public static Boolean isIsogram(String str) {
20
-        return null;
47
+
48
+        char arr[] = str.toCharArray();
49
+
50
+        Arrays.sort(arr);
51
+        for (int i = 0; i < str.length() - 1; i++) {
52
+            if (arr[i] == arr[i + 1])
53
+                return false;
54
+        }
55
+        return true;
21 56
     }
22 57
 
58
+
23 59
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
24
-        return null;
60
+        char arr[] = str.toCharArray();
61
+
62
+        for(int i = 0; i < arr.length; i++){
63
+            for(int j = 0; j <arr.length; j++){
64
+                if(arr[i] == arr[j]){
65
+                    return false;
66
+                }
67
+            }
68
+        }
69
+        return true;
25 70
     }
26 71
 
27 72
     public static String removeConsecutiveDuplicateCharacters(String str) {
28
-        return null;
73
+
74
+        StringBuilder builder = new StringBuilder();
75
+
76
+        char arr[] = str.toCharArray();
77
+
78
+        for(int i = 0; i < arr.length; i++){
79
+                if(arr[i] != arr[j]){
80
+                    builder.append(arr[i]);
81
+                }
82
+            }
83
+
84
+
85
+
86
+        return builder.toString();
29 87
     }
30 88
 
31 89
     public static String invertCasing(String str) {

+ 5
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java View File

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

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

@@ -1,9 +1,48 @@
1 1
 package rocks.zipcode.quiz5.objectorientation.account;
2 2
 
3
+import java.awt.*;
4
+import java.util.ArrayList;
5
+
3 6
 /**
4 7
  * @author leon on 27/12/2018.
5 8
  */
6
-public class BankAccount {
9
+public class BankAccount extends ArrayList implements Transactable{
10
+
11
+    Double val;
12
+
7 13
     public void setBalance(Double val) {
14
+        this.val = val;
15
+    }
16
+
17
+    @Override
18
+    public void deposit(Double amountToIncreaseBy){
19
+        try {
20
+            if(val >= amountToIncreaseBy && amountToIncreaseBy > 0) {
21
+                val += amountToIncreaseBy;
22
+            }else{
23
+                throw new IllegalArgumentException();
24
+            }
25
+        }catch (IllegalArgumentException e){
26
+            System.out.println("Insufficient Funds");
27
+            throw new IllegalArgumentException();
28
+        }    }
29
+
30
+    @Override
31
+    public void withdrawal(Double amountToDecreaseBy) {
32
+        try {
33
+            if(val >= amountToDecreaseBy && amountToDecreaseBy > 0) {
34
+                val -= amountToDecreaseBy;
35
+            }else{
36
+                throw new IllegalArgumentException();
37
+            }
38
+        }catch (IllegalArgumentException e){
39
+            System.out.println("Insufficient Funds");
40
+            throw new IllegalArgumentException();
41
+        }
42
+    }
43
+
44
+    @Override
45
+    public Double getBalance() {
46
+        return val;
8 47
     }
9 48
 }

+ 5
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java View File

@@ -4,6 +4,9 @@ package rocks.zipcode.quiz5.objectorientation.account;
4 4
  * @author leon on 30/12/2018.
5 5
  */
6 6
 public class Employee {
7
+
8
+    BankAccount bankAccount;
9
+
7 10
     public Employee() {
8 11
     }
9 12
 
@@ -11,10 +14,11 @@ public class Employee {
11 14
     }
12 15
 
13 16
     public BankAccount getBankAccount() {
14
-        return null;
17
+        return bankAccount;
15 18
     }
16 19
 
17 20
     public void setBankAccount(BankAccount bankAccount) {
21
+        this.bankAccount = bankAccount;
18 22
 
19 23
     }
20 24
 }