-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoop38.java
114 lines (97 loc) · 3.82 KB
/
oop38.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.util.Scanner;
class InvalidInpiut extends Exception{
public String toString() {
return "please enter the correct input";
}
}
class DivideBy0 extends Exception {
public String toString() {
return "Can not divide by Zero";
}
}
class MaxInput extends Exception {
public String toString() {
return "Enter value lower than 1lakh";
}
}
class MaxMultiplier extends Exception {
public String toString(){
return "Enter multiplier lower than 7k";
}
}
public class oop38 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a, b;
String s;
while (true) {
System.out.println("Enter + for Addition");
System.out.println("Enter - for Subtraction");
System.out.println("Enter * for Multiplication");
System.out.println("Enter / for Division");
s = sc.nextLine();
switch (s) {
case "+":
System.out.println("Enter value of Number 1");
a = sc.nextDouble();
System.out.println("Enter value of Number 2");
b = sc.nextDouble();
if (a >= 100000 || b >= 100000) {
System.out.println(new MaxInput().toString());
}
else if(a <= 100000 || b <= 100000){
System.out.println("Sum is = " + (a + b));
break;
}
case "*":
System.out.println("Enter value of Number 1");
a = sc.nextDouble();
System.out.println("Enter value of Number 2");
b = sc.nextDouble();
if (a >= 7000 || b >= 7000) {
System.out.println(new MaxMultiplier().toString());
}
else if(a <= 100000 || b <= 100000){
System.out.println("Multiplication = " + (a * b));
break;
}
case "/":
System.out.println("Enter value of Number 1");
a = sc.nextDouble();
System.out.println("Enter value of Number 2");
b = sc.nextDouble();
if (a >= 100000 || b >= 100000) {
System.out.println(new MaxInput().toString());
}
if (b == 0) {
System.out.println(new DivideBy0().toString());
}
else if(a <= 100000 || b <= 100000){
double div = a / b;
System.out.println("Division =" + div);
break;
}
case "-":
System.out.println("Enter value of Number 1");
a = sc.nextDouble();
System.out.println("Enter value of Number 2");
b = sc.nextDouble();
if (a >= 100000 || b >= 100000) {
System.out.println(new MaxInput().toString());
}
else if(a <= 100000 || b <= 100000){
System.out.println("Value of Subtraction = " + (a - b));
break;
}
default:
System.out.println("Please try again and enter a valid input.");
}
System.out.println("Do you want to continue? (yes/no)");
String continueInput = sc.next();
if (continueInput.equalsIgnoreCase("no")) {
break;
}
sc.nextLine(); // Consume the newline left in the buffer
}
}
}