Browse Source

pchai7-Done

Chaitali Patel 5 years ago
parent
commit
6233459539

+ 8
- 9
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java View File

@@ -13,15 +13,14 @@ public class ArrayUtils {
13 13
     }
14 14
 
15 15
     public static String[] removeMiddleElement(String[] values) {
16
-//        String[] str = new String[values.length-1];
17
-//        int j = 0;
18
-//        for (int i = 0; i < values.length-1; i++) {
19
-//            str[j] = values[i/2];
20
-//            j++;
21
-//        }
22
-//        return str;
23
-        values[ values.length/2 ] = values[ values.length - 1 ] ;
24
-        return values;
16
+        String[] str = new String[values.length-1];
17
+        int j = 0;
18
+        for (int i = 0; i < values.length-1; i++) {
19
+            str[j] = values[i/2];
20
+            j++;
21
+        }
22
+        return str;
23
+
25 24
     }
26 25
 
27 26
     public static String getLastElement(String[] values) {

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

@@ -1,6 +1,8 @@
1 1
 package rocks.zipcode.quiz5.fundamentals;
2 2
 
3 3
 import java.util.Arrays;
4
+import java.util.HashSet;
5
+import java.util.Set;
4 6
 
5 7
 /**
6 8
  * @author leon on 21/12/2018.
@@ -21,6 +23,7 @@ public class StringUtils {
21 23
 //        char c = cap.charAt(middle);
22 24
 //        return String.valueOf(c);
23 25
         return Character.toUpperCase(str.charAt(0)) + str.substring(1);
26
+
24 27
     }
25 28
 
26 29
     public static String lowerCaseMiddleCharacter(String str) {
@@ -37,22 +40,19 @@ public class StringUtils {
37 40
     }
38 41
 
39 42
     public static Boolean isIsogram(String str) {
40
-        str = str.toLowerCase();
41
-        int len = str.length();
42
-
43
-        char arr[] = str.toCharArray();
43
+        String[] ary = str.split("");
44
+        Set<String> mySet = new HashSet<String>(Arrays.asList(ary));
44 45
 
45
-        Arrays.sort(arr);
46
-        for (int i = 0; i < len - 1; i++) {
47
-            if (arr[i] == arr[i + 1])
48
-                return false;
46
+        if(str.length() == mySet.size()){
47
+            return true;
48
+        }else {
49
+            return false;
49 50
         }
50
-        return true;
51 51
 }
52 52
 
53 53
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
54
-        return (str.matches("(.)\\1"));
55
-        //return (str.matches(".*(.)\\1.*"));
54
+       // return (str.matches("(.)\\1"));
55
+        return (str.matches(".*(.)\\1.*"));
56 56
     }
57 57
 
58 58
     public static String removeConsecutiveDuplicateCharacters(String str) {

+ 0
- 15
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java View File

@@ -16,19 +16,4 @@ public class Account extends BankAccount implements Transactable{
16 16
     public void setId(Long id) {
17 17
         this.Id = id;
18 18
     }
19
-
20
-    @Override
21
-    public void deposit(Double amountToIncreaseBy) {
22
-
23
-    }
24
-
25
-    @Override
26
-    public void withdrawal(Double amountToDecreaseBy) {
27
-
28
-    }
29
-
30
-    @Override
31
-    public Double getBalance() {
32
-        return null;
33
-    }
34 19
 }

+ 8
- 6
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java View File

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

+ 16
- 7
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java View File

@@ -5,8 +5,10 @@ package rocks.zipcode.quiz5.objectorientation.account;
5 5
  */
6 6
 public class Employee extends Account implements Worker,Transactable {
7 7
     private BankAccount bankAccount;
8
-    private double numberOfHoursWorkedSoFar;
9
-    private Double hourlyWage;
8
+    private Double numberOfHoursWorkedSoFar = 0.0;
9
+    private Double hourlyWage = 0.0;
10
+    private Double BankAccountBalance = 0.0;
11
+    Double InitialAmount = 0.0;
10 12
 
11 13
     public Employee() {
12 14
     }
@@ -14,6 +16,13 @@ public class Employee extends Account implements Worker,Transactable {
14 16
     public Employee(BankAccount bankAccount) {
15 17
     }
16 18
 
19
+    public Employee( Worker workerEmployee, Transactable transactableEmployee, Transactable bankAccount) {
20
+        super();
21
+        workerEmployee = workerEmployee;
22
+        transactableEmployee = transactableEmployee;
23
+        bankAccount = bankAccount;
24
+    }
25
+
17 26
     public BankAccount getBankAccount() {
18 27
         return bankAccount;
19 28
     }
@@ -43,22 +52,22 @@ public class Employee extends Account implements Worker,Transactable {
43 52
 
44 53
     @Override
45 54
     public Double getMoneyEarned() {
46
-        Double earned = hourlyWage * numberOfHoursWorkedSoFar;
47
-        return earned;
55
+        BankAccountBalance = hourlyWage * numberOfHoursWorkedSoFar;
56
+        return BankAccountBalance;
48 57
     }
49 58
 
50 59
     @Override
51 60
     public void deposit(Double amountToIncreaseBy) {
52
-        getMoneyEarned();
61
+        BankAccountBalance = amountToIncreaseBy;
53 62
     }
54 63
 
55 64
     @Override
56 65
     public void withdrawal(Double amountToDecreaseBy) {
57
-
66
+        BankAccountBalance = amountToDecreaseBy;
58 67
     }
59 68
 
60 69
     @Override
61 70
     public Double getBalance() {
62
-        return null;
71
+        return this.BankAccountBalance;
63 72
     }
64 73
 }