Skip to content

Commit 50bfe9e

Browse files
committed
added JavaCalculator\src\com\mateo\main\Calculations.java
1 parent c4cac74 commit 50bfe9e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.mateo.main;
2+
3+
public class Calculations {
4+
5+
enum Operation {
6+
ADD, SUBTRACT, MULTIPLY, DIVIDE, SQUARE,
7+
}
8+
9+
public static int calculate(Operation op, int A, int B) {
10+
switch (op) {
11+
case ADD:
12+
return add(A, B);
13+
case SUBTRACT:
14+
return subtract(A, B);
15+
case MULTIPLY:
16+
return multiply(A, B);
17+
case DIVIDE:
18+
return divide(A, B);
19+
case SQUARE:
20+
return square(A,B);
21+
}
22+
23+
throw new RuntimeException("Unsupported exception");
24+
25+
}
26+
27+
28+
private static int add(int a, int b) {
29+
// TODO Auto-generated method stub
30+
return a + b;
31+
}
32+
33+
private static int multiply(int a, int b) {
34+
// TODO Auto-generated method stub
35+
return a * b;
36+
}
37+
38+
private static int subtract(int a, int b) {
39+
// TODO Auto-generated method stub
40+
return a - b;
41+
}
42+
43+
private static int divide(int a, int b) {
44+
// TODO Auto-generated method stub
45+
return a / b;
46+
47+
}
48+
private static int square(int a, int b) {
49+
// TODO Auto-generated method stub
50+
return (a*a);
51+
}
52+
53+
}

0 commit comments

Comments
 (0)