forked from ikismail/JavaBasicPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainProg.java
More file actions
69 lines (53 loc) · 1.46 KB
/
mainProg.java
File metadata and controls
69 lines (53 loc) · 1.46 KB
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;
class calcFuncImpl {
public int addFunc(int i1, int i2) {
return i1 + i2;
}
public int subtFunc(int i1, int i2) {
return i1 - i2;
}
public int multiFunc(int i1, int i2) {
return i1 * i2;
}
public double dividFunc(double i1, double i2) {
double z = 0;
try {
z = i1 / i2;
} catch (Exception e) {
System.out.println("Cant Divide a number by 0");
}
return z;
}
calcFuncImpl(int i1, int i2, int choice) {
switch (choice) {
case 1:
System.out.println("Addition of " + i1 + " + " + i2 + " is " + addFunc(i1, i2));
break;
case 2:
System.out.println("Subtraction of " + i1 + " - " + i2 + " is " + subtFunc(i1, i2));
break;
case 3:
System.out.println("Multiplication of " + i1 + " * " + i2 + " is " + multiFunc(i1, i2));
break;
case 4:
System.out.println("Divisioin of " + i1 + " / " + i2 + " is " + dividFunc(i1, i2));
break;
default:
break;
}
}
}
public class mainProg {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please choose the Function");
System.out.println("1.Addition \n2.Subtraction \n3.Multiplication \n4.Division");
int choice = sc.nextInt();
System.out.println("Enter Input - 1");
int input1 = sc.nextInt();
System.out.println("Enter Input - 2");
int input2 = sc.nextInt();
new calcFuncImpl(input1, input2, choice);
sc.close();
}
}