forked from akash-coded/C133-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationsOnCommandLineArgs.java
More file actions
45 lines (41 loc) · 999 Bytes
/
OperationsOnCommandLineArgs.java
File metadata and controls
45 lines (41 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
enum Operator {
ADD, SUBTRACT, MULTIPLY, DIVIDE
}
class Operations {
int a;
int b;
Operator opr;
public Operations(int a, int b, Operator opr) {
this.a = a;
this.b = b;
this.opr = opr;
}
public int calculate() {
switch (opr) {
case ADD -> {
return (a + b);
}
case SUBTRACT -> {
return (a - b);
}
case MULTIPLY -> {
return (a * b);
}
case DIVIDE -> {
return a / b;
}
default -> {
return -1;
}
}
}
}
public class OperationsOnCommandLineArgs {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
Operator opr = Operator.valueOf(args[2]);
Operations c = new Operations(a, b, opr);
System.out.println(c.calculate());
}
}