Browse Source

pre-merge

Whitney Martinez 5 years ago
parent
commit
418ebcf347

+ 8
- 0
src/main/java/rocks/zipcode/quiz5/collections/Bank.java View File

@@ -11,6 +11,14 @@ import java.util.List;
11 11
 public class Bank  {
12 12
     List<BankAccount> bankaccounts = new ArrayList<>();
13 13
 
14
+    public Bank() {
15
+    }
16
+
17
+    public Bank(List<BankAccount> bankaccounts) {
18
+
19
+        this.bankaccounts = bankaccounts;
20
+    }
21
+
14 22
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
15 23
 
16 24
 

+ 2
- 0
src/main/java/rocks/zipcode/quiz5/collections/Food.java View File

@@ -16,9 +16,11 @@ public class Food {
16 16
 
17 17
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
18 18
 
19
+
19 20
         return null;
20 21
     }
21 22
 
22 23
     public void applySpice(Spice spice) {
24
+        listing.add(spice);
23 25
     }
24 26
 }

+ 70
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java View File

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

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

@@ -3,11 +3,15 @@ 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
+
8
+    private 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
 }

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

@@ -1,9 +1,39 @@
1 1
 package rocks.zipcode.quiz5.objectorientation.account;
2 2
 
3
+
4
+
3 5
 /**
4 6
  * @author leon on 27/12/2018.
5 7
  */
6
-public class BankAccount {
8
+public class BankAccount extends Account implements Transactable {
9
+
10
+    private Double val;
11
+
12
+    public BankAccount() {
13
+    }
14
+
15
+    public BankAccount(Double val) {
16
+        this.val = val;
17
+    }
18
+
7 19
     public void setBalance(Double val) {
20
+
21
+        this.val = val;
22
+
23
+    }
24
+
25
+    @Override
26
+    public void deposit(Double amountToIncreaseBy) {
27
+        this.val += amountToIncreaseBy;
28
+    }
29
+
30
+    @Override
31
+    public void withdrawal(Double amountToDecreaseBy) {
32
+        this.val -= amountToDecreaseBy;
33
+    }
34
+
35
+    @Override
36
+    public Double getBalance() {
37
+        return this.val;
8 38
     }
9 39
 }

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

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

+ 1
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Transactable.java View File

@@ -4,6 +4,7 @@ package rocks.zipcode.quiz5.objectorientation.account;
4 4
  * @author leon on 30/12/2018.
5 5
  */
6 6
 public interface Transactable {
7
+
7 8
     void deposit(Double amountToIncreaseBy);
8 9
     void withdrawal(Double amountToDecreaseBy);
9 10
     Double getBalance();

+ 1
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Worker.java View File

@@ -4,6 +4,7 @@ package rocks.zipcode.quiz5.objectorientation.account;
4 4
  * @author leon on 30/12/2018.
5 5
  */
6 6
 public interface Worker {
7
+
7 8
     void increaseHoursWorked(Double numberOfHours);
8 9
     Double getHoursWorked();
9 10
     Double getHourlyWage();