Browse Source

calculator

Seth 5 years ago
parent
commit
c3c0288f7d

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

9
  * @author leon on 27/12/2018.
9
  * @author leon on 27/12/2018.
10
  */
10
  */
11
 public class Food {
11
 public class Food {
12
+
12
     public List<Spice> getAllSpices() {
13
     public List<Spice> getAllSpices() {
13
         return null;
14
         return null;
14
     }
15
     }

+ 20
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java View File

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