Repository navigation
Expand file tree
/
Copy pathDoCalc.java
More file actions
53 lines (48 loc) · 2.07 KB
/
Copy pathDoCalc.java
File metadata and controls
53 lines (48 loc) · 2.07 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
import java.util.Scanner;
class DoCalc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Calculator calc = new Calculator();
int choice;
do {
System.out.println("\nMENU");
System.out.println("1. Addition");
System.out.println("2. Substraction");
System.out.println("3. Multiplication");
System.out.println("4. Division");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
if (choice == 1) {
System.out.print("Enter the first number: ");
int x = sc.nextInt();
System.out.print("Enter the second number: ");
int y = sc.nextInt();
System.out.println("Addition = " + calc.add(x, y));
} else if (choice == 2) {
System.out.print("Enter the first number: ");
int x = sc.nextInt();
System.out.print("Enter the second number: ");
int y = sc.nextInt();
System.out.println("Substraction = " + calc.sub(x, y));
} else if (choice == 3) {
System.out.print("Enter the first number: ");
int x = sc.nextInt();
System.out.print("Enter the second number: ");
int y = sc.nextInt();
System.out.println("Multiply = " + calc.multiply(x, y));
} else if (choice == 4) {
System.out.print("Enter the first number: ");
int x = sc.nextInt();
System.out.print("Enter the second number: ");
int y = sc.nextInt();
System.out.println("Division = " + calc.divide(x, y));
} else if (choice == 5) {
System.out.println("Exited Successfully!!");
} else {
System.out.println("Invalid Choice!");
}
} while (choice != 5);
sc.close();
}
}