Kaynağa Gözat

Curtis Cook's Quiz5 Completed

curtiscook 5 yıl önce
ebeveyn
işleme
240c7ce370

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Dosyayı Görüntüle

@@ -34,7 +34,7 @@ public class Calculator {
34 34
     }
35 35
 
36 36
     public static Double subtract(Double value1, Double value2) {
37
-        return Double.valueOf(String.format("%.1f", value1 - value2));
37
+        return value1 - value2;
38 38
     }
39 39
 
40 40
     public static Double divide(Double divisor, Double dividend) {

+ 38
- 5
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Dosyayı Görüntüle

@@ -18,22 +18,55 @@ public class StringUtils {
18 18
     }
19 19
 
20 20
     public static String lowerCaseMiddleCharacter(String str) {
21
-        return null;
21
+        StringBuilder sb = new StringBuilder(str);
22
+        int index = str.length() / 2;
23
+        Character middleChar = Character.toLowerCase(StringUtils.getMiddleCharacter(str));
24
+        sb.deleteCharAt(index);
25
+        sb.insert(index, middleChar);
26
+        return sb.toString();
22 27
     }
23 28
 
24 29
     public static Boolean isIsogram(String str) {
25
-        return null;
30
+        for (int i = 0; i < str.length(); i++) {
31
+            String letter = String.valueOf(str.charAt(i));
32
+            if (str.substring(i + 1).contains(letter)) {
33
+                return false;
34
+            }
35
+        }
36
+        return true;
26 37
     }
27 38
 
28 39
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
29
-        return null;
40
+        for (int i = 0; i < str.length() - 1; i++) {
41
+            if (str.charAt(i) == str.charAt(i + 1)) {
42
+                return true;
43
+            }
44
+        }
45
+        return false;
30 46
     }
31 47
 
32 48
     public static String removeConsecutiveDuplicateCharacters(String str) {
33
-        return null;
49
+        StringBuilder sb = new StringBuilder();
50
+        for (int i = 0; i < str.length() - 1; i++) {
51
+            if (str.charAt(i) == str.charAt(i + 1)) {
52
+                i++;
53
+            } else {
54
+                sb.append(str.charAt(i));
55
+            }
56
+        }
57
+        sb.append(str.charAt(str.length() - 1));
58
+        return sb.toString();
34 59
     }
35 60
 
36 61
     public static String invertCasing(String str) {
37
-        return null;
62
+        StringBuilder sb = new StringBuilder();
63
+        for (int i = 0; i < str.length(); i++) {
64
+            if (Character.isUpperCase(str.charAt(i))) {
65
+                sb.append(Character.toLowerCase(str.charAt(i)));
66
+            } else {
67
+                sb.append(Character.toUpperCase(str.charAt(i)));
68
+            }
69
+        }
70
+        return sb.toString();
38 71
     }
39 72
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java Dosyayı Görüntüle

@@ -3,7 +3,7 @@ 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 7
     public Long getId() {
8 8
         return null;
9 9
     }

+ 25
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java Dosyayı Görüntüle

@@ -3,7 +3,31 @@ 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
+    Double balance = 0.0;
8
+
7 9
     public void setBalance(Double val) {
10
+        balance = val;
11
+    }
12
+
13
+    @Override
14
+    public void deposit(Double amountToIncreaseBy) {
15
+        if (amountToIncreaseBy < 0) {
16
+            throw new IllegalArgumentException();
17
+        }
18
+        balance += amountToIncreaseBy;
19
+    }
20
+
21
+    @Override
22
+    public void withdrawal(Double amountToDecreaseBy) {
23
+        if (amountToDecreaseBy < 0 || amountToDecreaseBy > balance) {
24
+            throw new IllegalArgumentException();
25
+        }
26
+        balance -= amountToDecreaseBy;
27
+    }
28
+
29
+    @Override
30
+    public Double getBalance() {
31
+        return balance;
8 32
     }
9 33
 }

+ 47
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java Dosyayı Görüntüle

@@ -3,18 +3,63 @@ 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 Transactable, Worker{
7
+    BankAccount bankAccount;
8
+    Double hours;
9
+    Double wage;
10
+
7 11
     public Employee() {
12
+        bankAccount = new BankAccount();
13
+        hours = 0.0;
14
+        wage = 35.0;
8 15
     }
9 16
 
10 17
     public Employee(BankAccount bankAccount) {
18
+        this.bankAccount = bankAccount;
19
+        hours = 0.0;
20
+        wage = 35.0;
11 21
     }
12 22
 
13 23
     public BankAccount getBankAccount() {
14
-        return null;
24
+        return bankAccount;
15 25
     }
16 26
 
17 27
     public void setBankAccount(BankAccount bankAccount) {
28
+        this.bankAccount = bankAccount;
29
+    }
30
+
31
+    @Override
32
+    public void deposit(Double amountToIncreaseBy) {
33
+        bankAccount.deposit(amountToIncreaseBy);
34
+    }
35
+
36
+    @Override
37
+    public void withdrawal(Double amountToDecreaseBy) {
38
+        bankAccount.withdrawal(amountToDecreaseBy);
39
+    }
40
+
41
+    @Override
42
+    public Double getBalance() {
43
+        return bankAccount.getBalance();
44
+    }
45
+
46
+    @Override
47
+    public void increaseHoursWorked(Double numberOfHours) {
48
+        hours += numberOfHours;
49
+    }
50
+
51
+    @Override
52
+    public Double getHoursWorked() {
53
+        return hours;
54
+    }
55
+
56
+    @Override
57
+    public Double getHourlyWage() {
58
+        return wage;
59
+    }
18 60
 
61
+    @Override
62
+    public Double getMoneyEarned() {
63
+        return hours * wage;
19 64
     }
20 65
 }