Skip to content

Commit 33574bf

Browse files
authored
CalculatorProgram
1 parent 10918cd commit 33574bf

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

mainProg.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import java.util.Scanner;
2+
3+
class calcFuncImpl {
4+
5+
public int addFunc(int i1, int i2) {
6+
7+
return i1 + i2;
8+
}
9+
10+
public int subtFunc(int i1, int i2) {
11+
return i1 - i2;
12+
}
13+
14+
public int multiFunc(int i1, int i2) {
15+
return i1 * i2;
16+
}
17+
18+
public double dividFunc(int i1, int i2) {
19+
double z = 0;
20+
try {
21+
z = i1 / i2;
22+
} catch (Exception e) {
23+
System.out.println("Cant Divide a number by 0");
24+
}
25+
return z;
26+
27+
}
28+
29+
calcFuncImpl(int i1, int i2, int choice) {
30+
switch (choice) {
31+
case 1:
32+
System.out.println("Addition of " + i1 + " + " + i2 + " is " + addFunc(i1, i2));
33+
break;
34+
case 2:
35+
System.out.println("Subtraction of " + i1 + " - " + i2 + " is " + subtFunc(i1, i2));
36+
break;
37+
case 3:
38+
System.out.println("Multiplication of " + i1 + " * " + i2 + " is " + multiFunc(i1, i2));
39+
break;
40+
case 4:
41+
System.out.println("Divisioin of " + i1 + " / " + i2 + " is " + dividFunc(i1, i2));
42+
break;
43+
default:
44+
break;
45+
}
46+
}
47+
48+
}
49+
50+
public class mainProg {
51+
52+
public static void main(String[] args) {
53+
54+
Scanner sc = new Scanner(System.in);
55+
56+
System.out.println("Please choose the Function");
57+
System.out.println("1.Addition \n2.Subtraction \n3.Multiplication \n4.Division");
58+
int choice = sc.nextInt();
59+
System.out.println("Enter Input - 1");
60+
int input1 = sc.nextInt();
61+
System.out.println("Enter Input - 2");
62+
int input2 = sc.nextInt();
63+
64+
new calcFuncImpl(input1, input2, choice);
65+
66+
sc.close();
67+
68+
}
69+
}

0 commit comments

Comments
 (0)