NiraParikh 5 년 전
부모
커밋
58844d4e22

+ 11
- 6
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java 파일 보기

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.quiz5.arrays;
2 2
 
3
+import java.lang.reflect.Array;
3 4
 import java.util.Arrays;
4 5
 
5 6
 /**
@@ -15,14 +16,18 @@ public class ArrayUtils {
15 16
 
16 17
     public static String[] removeMiddleElement(String[] values) {
17 18
 
18
-//        String newString[] = new String[values.length - 1];
19
-//        for (int i = 0; i < values.length/2; i++) {
20
-//           newString +=(! )
21
-////        }
22
-////        return newString;
19
+        int middleStart = (values.length - 1) / 2;
20
+        int middleEnd = (values.length - 1) - middleStart;
21
+        int elementsToRemove = middleEnd - middleStart + 1;
22
+
23
+        int[] result = new int[values.length - elementsToRemove];
24
+        System.arraycopy(values, 0, result, 0, middleStart);
25
+        System.arraycopy(values, middleEnd + 1, result, middleStart, middleStart);
26
+
27
+        return values;
28
+//
23 29
 
24 30
 
25
-             return Arrays.copyOf(values, values.length - 1);
26 31
     }
27 32
 
28 33
     public static String getLastElement(String[] values) {

+ 7
- 2
src/main/java/rocks/zipcode/quiz5/collections/Bank.java 파일 보기

@@ -1,5 +1,6 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
+import rocks.zipcode.quiz5.objectorientation.account.Account;
3 4
 import rocks.zipcode.quiz5.objectorientation.account.BankAccount;
4 5
 
5 6
 import java.util.ArrayList;
@@ -8,7 +9,7 @@ import java.util.List;
8 9
 /**
9 10
  * @author leon on 27/12/2018.
10 11
  */
11
-public class Bank {
12
+public class Bank extends Account {
12 13
     private Integer indexNumber;
13 14
     private BankAccount bankAccount;
14 15
 
@@ -17,12 +18,16 @@ public class Bank {
17 18
     Bank bank = new Bank();
18 19
 
19 20
     public BankAccount removeBankAccountByIndex(Integer indexNumber) {
20
-//       return list.remove(indexNumber);
21
+        if(list.contains(indexNumber)){
22
+            list.remove(indexNumber);
23
+        }
21 24
         return null;
25
+
22 26
     }
23 27
 
24 28
     public void addBankAccount(BankAccount bankAccount) {
25 29
        list.add(bankAccount);
30
+        bank.addBankAccount(bankAccount);
26 31
 
27 32
     }
28 33
 

+ 2
- 0
src/main/java/rocks/zipcode/quiz5/collections/Food.java 파일 보기

@@ -12,6 +12,7 @@ import java.util.Map;
12 12
 public class Food implements Spice {
13 13
     private Spice spice;
14 14
 
15
+
15 16
     List<Spice> list = new ArrayList<>();
16 17
 
17 18
     public List<Spice> getAllSpices() {
@@ -32,6 +33,7 @@ public class Food implements Spice {
32 33
     }
33 34
 
34 35
     public void setSpice(Spice spice) {
36
+
35 37
         this.spice = spice;
36 38
     }
37 39
 }

+ 3
- 3
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java 파일 보기

@@ -35,10 +35,10 @@ public class Calculator {
35 35
 
36 36
     public static Double add(Double value1, Double value2) {
37 37
 //        double sum = value1 + value2;
38
-          Math.ceil(value1);
39
-          Math.ceil(value2);
38
+          Math.floor(value1);
39
+          Math.floor(value2);
40 40
         double sum = value1 + value2;
41
-        return Math.floor(sum);
41
+        return sum;
42 42
 
43 43
     }
44 44
 

+ 14
- 9
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java 파일 보기

@@ -37,6 +37,8 @@ public class StringUtils {
37 37
         return true;
38 38
 }
39 39
 
40
+
41
+
40 42
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
41 43
             for(char c : str.toCharArray())
42 44
                 if(c != str.charAt(0)) return false;
@@ -45,15 +47,18 @@ public class StringUtils {
45 47
     }
46 48
 
47 49
     public static String removeConsecutiveDuplicateCharacters(String str) {
48
-        String temp = "";
49
-        int length = str.length();
50
-        for (int i = 0; i < length; i++) {
51
-            if (str.charAt(i) != ' ') {
52
-                char curr_letter = str.charAt(i);
53
-                temp += curr_letter;
54
-                str = str.replace(str.charAt(i), ' ');
55
-            }
56
-        }
50
+//        String temp = "";
51
+//        int length = str.length();
52
+//        for (int i = 0; i < length; i++) {
53
+//            if (str.charAt(i) != ' ') {
54
+//                char curr_letter = str.charAt(i);
55
+//                temp += curr_letter;
56
+//                str = str.replace(str.charAt(i), ' ');
57
+//            }
58
+//        }
59
+
60
+        System.out.println(str.replaceAll("(.)\\1{1,}", "$1"));
61
+
57 62
         return str;
58 63
     }
59 64
 

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java 파일 보기

@@ -2,5 +2,5 @@ package rocks.zipcode.quiz5.objectorientation;
2 2
 
3 3
 import rocks.zipcode.quiz5.collections.Food;
4 4
 
5
-public class Curry extends Food implements Spice {
5
+public class Curry implements Spice {
6 6
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Ginger.java 파일 보기

@@ -5,5 +5,5 @@ import rocks.zipcode.quiz5.collections.Food;
5 5
 /**
6 6
  * @author leon on 27/12/2018.
7 7
  */
8
-public class Ginger extends Food implements Spice{
8
+public class Ginger extends Food implements Spice {
9 9
 }

+ 2
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java 파일 보기

@@ -3,7 +3,8 @@ 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 8
     private Long id;
8 9
 
9 10
     public Long getId() {

+ 17
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java 파일 보기

@@ -3,10 +3,26 @@ 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 7
     private Double val;
8 8
 
9 9
     public void setBalance(Double val) {
10 10
         this.val = val;
11 11
     }
12
+
13
+    @Override
14
+    public void deposit(Double amountToIncreaseBy) {
15
+
16
+
17
+    }
18
+
19
+    @Override
20
+    public void withdrawal(Double amountToDecreaseBy) {
21
+
22
+    }
23
+
24
+    @Override
25
+    public Double getBalance() {
26
+        return val;
27
+    }
12 28
 }

+ 31
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java 파일 보기

@@ -3,12 +3,22 @@ package rocks.zipcode.quiz5.objectorientation.account;
3 3
 /**
4 4
  * @author leon on 30/12/2018.
5 5
  */
6
-public class Employee extends Account implements Worker {
6
+public class Employee extends Account implements Worker, Transactable{
7 7
     private BankAccount bankAccount;
8 8
     private Double numberOfHours;
9
+    private Double expectedBalance;
10
+
11
+    public Employee(BankAccount bankAccount, Double numberOfHours, Double expectedBalance) {
12
+        this.bankAccount = bankAccount;
13
+        this.numberOfHours = numberOfHours;
14
+        this.expectedBalance = expectedBalance;
15
+    }
9 16
 
10 17
     public Employee() {
11
-        this.bankAccount = null;
18
+    }
19
+
20
+    public Employee(Double numberOfHours) {
21
+        this.numberOfHours = numberOfHours;
12 22
     }
13 23
 
14 24
     public Employee(BankAccount bankAccount, Double numberOfHours) {
@@ -52,4 +62,23 @@ public class Employee extends Account implements Worker {
52 62
     public void setNumberOfHours(Double numberOfHours) {
53 63
         this.numberOfHours = numberOfHours;
54 64
     }
65
+
66
+    @Override
67
+    public void deposit(Double amountToIncreaseBy) {
68
+
69
+    }
70
+
71
+    @Override
72
+    public void withdrawal(Double amountToDecreaseBy) {
73
+
74
+    }
75
+
76
+    @Override
77
+    public Double getBalance() {
78
+        return expectedBalance;
79
+    }
80
+
81
+    public void setExpectedBalance(Double expectedBalance) {
82
+        this.expectedBalance = expectedBalance;
83
+    }
55 84
 }