-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathcalculator.java
69 lines (54 loc) · 1.33 KB
/
calculator.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Scanner;
/**
* @author jacobjohn
*
*/
class calculate {
public float add(float n1, float n2) {
return n1 + n2;
}
public float sub(float n1, float n2) {
return n1 - n2;
}
public float mul(float n1, float n2) {
return n1 * n2;
}
public float div(float n1, float n2) {
return n1 / n2;
}
public float mod(float n1, float n2) {
return n1 % n2;
}
}
public class calculator {
public static void main(String[] args) {
System.out.println("The Simple Calculator Application");
System.out.println("1. +" + "\n" + "2. -" + "\n" + "3. *" + "\n" + "4. /" + "\n" + "5. %");
System.out.print("Enter your choice: ");
Scanner in = new Scanner(System.in);
int cal = in.nextInt();
System.out.print("Enter operand 1: ");
float oper1 = in.nextInt();
System.out.print("Enter operand 2: ");
float oper2 = in.nextInt();
calculate calc = new calculate();
switch (cal) {
case 1:
System.out.println("Answer: " + calc.add(oper1, oper2));
break;
case 2:
System.out.println("Answer: " + calc.sub(oper1, oper2));
break;
case 3:
System.out.println("Answer: " + calc.mul(oper1, oper2));
break;
case 4:
System.out.println("Answer: " + calc.div(oper1, oper2));
break;
case 5:
System.out.println("Answer: " + calc.mod(oper1, oper2));
break;
}
in.close();
}
}