Ver código fonte

pre-merge commit

Chaitali Patel 5 anos atrás
pai
commit
1357e6a44d

+ 23
- 4
src/main/java/rocks/zipcode/quiz5/arrays/ArrayUtils.java Ver arquivo

@@ -5,18 +5,37 @@ package rocks.zipcode.quiz5.arrays;
5 5
  */
6 6
 public class ArrayUtils {
7 7
     public static String getMiddleElement(String[] values) {
8
-        return null;
8
+        String a = "";
9
+        if(values.length>1) {
10
+            a+=values[values.length/2];
11
+        }
12
+        return a;
9 13
     }
10 14
 
11 15
     public static String[] removeMiddleElement(String[] values) {
12
-        return null;
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;
13 25
     }
14 26
 
15 27
     public static String getLastElement(String[] values) {
16
-        return null;
28
+        String lastOne = values[values.length-1];
29
+        return lastOne;
17 30
     }
18 31
 
19 32
     public static String[] removeLastElement(String[] values) {
20
-        return null;
33
+        String[] str = new String[values.length-1];
34
+        int j = 0;
35
+        for (int i = 0; i < values.length-1; i++) {
36
+            str[j] = values[i];
37
+            j++;
38
+        }
39
+        return str;
21 40
     }
22 41
 }

+ 20
- 2
src/main/java/rocks/zipcode/quiz5/collections/Bank.java Ver arquivo

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

+ 7
- 2
src/main/java/rocks/zipcode/quiz5/collections/Food.java Ver arquivo

@@ -2,15 +2,20 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.Spice;
4 4
 
5
+import java.util.ArrayList;
5 6
 import java.util.List;
6 7
 import java.util.Map;
7 8
 
8 9
 /**
9 10
  * @author leon on 27/12/2018.
10 11
  */
11
-public class Food {
12
+public class Food implements Spice{
13
+    List<Spice> spice = new ArrayList<>();
12 14
     public List<Spice> getAllSpices() {
13
-        return null;
15
+        for (int i = 0; i < spice.size(); i++) {
16
+            System.out.println(spice.get(i));
17
+        }
18
+        return spice;
14 19
     }
15 20
 
16 21
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {

+ 15
- 1
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Ver arquivo

@@ -1,12 +1,26 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
+import java.util.HashMap;
3 4
 import java.util.Map;
4 5
 
5 6
 public class WordCounter {
7
+    Map<String,Integer> map = new HashMap<>();
8
+    private String[] strings;
9
+
6 10
     public WordCounter(String... strings) {
7 11
     }
8 12
 
9 13
     public Map<String, Integer> getWordCountMap() {
10
-        return null;
14
+        for (String s: strings) {
15
+
16
+            if (!map.containsKey(s)) {  // first time we've seen this string
17
+                map.put(s, 1);
18
+            }
19
+            else {
20
+                int count = map.get(s);
21
+                map.put(s, count + 1);
22
+            }
23
+        }
24
+        return map;
11 25
     }
12 26
 }

+ 20
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Ver arquivo

@@ -5,31 +5,44 @@ package rocks.zipcode.quiz5.fundamentals;
5 5
  */
6 6
 public class Calculator {
7 7
     public static Double squareRoot(Double value) {
8
-        return null;
8
+        double root = Math.sqrt(value);
9
+        return root;
9 10
     }
10 11
 
11 12
     public static Double square(Double value) {
12
-        return null;
13
+        double sqrt = Math.pow(value,2);
14
+        return sqrt;
13 15
     }
14 16
 
15 17
     public static Double[] squareRoots(Double... value) {
16
-        return null;
18
+        Double[] result = new Double[value.length];
19
+        for( int i = 0; i < value.length ; i++ ) {
20
+            result[i] = Math.sqrt(value[i]);
21
+        }
22
+        return result;
17 23
     }
18 24
 
19 25
     public static Double[] squares(Double... values) {
20
-        return null;
26
+        Double[] result = new Double[values.length];
27
+        for( int i = 0; i < values.length ; i++ ) {
28
+            result[i] = Math.pow(values[i],2);
29
+        }
30
+        return result;
31
+
21 32
     }
22 33
 
23 34
     public static Double add(Double value1, Double value2) {
24
-        return null;
35
+        double sum = value1 + value2;
36
+        //double roundOff = Math.round(sum*100)/100;
37
+        return sum;
25 38
     }
26 39
 
27 40
     public static Double subtract(Double value1, Double value2) {
28
-        return null;
41
+        return value1-value2;
29 42
     }
30 43
 
31 44
 
32 45
     public static Double divide(Double divisor, Double dividend) {
33
-        return null;
46
+        return ((double)divisor/dividend);
34 47
     }
35 48
 }

+ 53
- 8
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java Ver arquivo

@@ -1,34 +1,79 @@
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
+        int stringLength = string.length() ;
11
+        int middle = stringLength/2 ;
12
+        char c = string.charAt(middle);
13
+        return c;
9 14
     }
10 15
 
11 16
     public static String capitalizeMiddleCharacter(String str) {
12
-        return null;
17
+//        String cap = str.toUpperCase();
18
+//        System.out.println(cap);
19
+//        int stringLength = str.length();
20
+//        int middle = stringLength/2 ;
21
+//        char c = cap.charAt(middle);
22
+//        return String.valueOf(c);
23
+        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
13 24
     }
14 25
 
15 26
     public static String lowerCaseMiddleCharacter(String str) {
16
-        return null;
27
+//        String cap = str.toLowerCase();
28
+//        System.out.println(cap);
29
+//        int stringLength = str.length();
30
+//        int middle = stringLength/2 ;
31
+//        char c = cap.charAt(middle);
32
+//        return String.valueOf(c);
33
+
34
+        String test = str;
35
+        test = test.substring(0,2) + test.substring(2,3).toLowerCase()+ test.substring(3);
36
+        return test;
17 37
     }
18 38
 
19 39
     public static Boolean isIsogram(String str) {
20
-        return null;
21
-    }
40
+        str = str.toLowerCase();
41
+        int len = str.length();
42
+
43
+        char arr[] = str.toCharArray();
44
+
45
+        Arrays.sort(arr);
46
+        for (int i = 0; i < len - 1; i++) {
47
+            if (arr[i] == arr[i + 1])
48
+                return false;
49
+        }
50
+        return true;
51
+}
22 52
 
23 53
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
24
-        return null;
54
+        return (str.matches("(.)\\1"));
55
+        //return (str.matches(".*(.)\\1.*"));
25 56
     }
26 57
 
27 58
     public static String removeConsecutiveDuplicateCharacters(String str) {
28
-        return null;
59
+        return str.replaceAll("(.)\\1+", "$1");
60
+
29 61
     }
30 62
 
31 63
     public static String invertCasing(String str) {
32
-        return null;
64
+        char[] chars = str.toCharArray();
65
+        for (int i = 0; i < chars.length; i++)
66
+        {
67
+            char c = chars[i];
68
+            if (Character.isUpperCase(c))
69
+            {
70
+                chars[i] = Character.toLowerCase(c);
71
+            }
72
+            else if (Character.isLowerCase(c))
73
+            {
74
+                chars[i] = Character.toUpperCase(c);
75
+            }
76
+        }
77
+        return new String(chars);
33 78
     }
34 79
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java Ver arquivo

@@ -1,4 +1,4 @@
1 1
 package rocks.zipcode.quiz5.objectorientation;
2 2
 
3
-public class Curry {
3
+public class Curry implements Spice{
4 4
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Ginger.java Ver arquivo

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Ginger {
6
+public class Ginger implements Spice{
7 7
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Pepper.java Ver arquivo

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Pepper {
6
+public class Pepper implements Spice{
7 7
 }

+ 23
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Account.java Ver arquivo

@@ -3,11 +3,32 @@ 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 extends BankAccount implements Transactable{
7
+    private Long Id;
8
+
9
+    public Account() {
10
+    }
11
+
7 12
     public Long getId() {
8
-        return null;
13
+        return Id;
9 14
     }
10 15
 
11 16
     public void setId(Long id) {
17
+        this.Id = id;
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;
12 33
     }
13 34
 }

+ 28
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/account/BankAccount.java Ver arquivo

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

+ 46
- 2
src/main/java/rocks/zipcode/quiz5/objectorientation/account/Employee.java Ver arquivo

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