-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
339 lines (319 loc) · 5.95 KB
/
calculator.java
File metadata and controls
339 lines (319 loc) · 5.95 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package calculator;
import java.util.Scanner;
public class calculator {
static int x,y,z;
static boolean x1,y1,z1;
calculator(int x,int y, int z)
{
this.x = x;
this.y = y;
this.z=z;
}
void add()
{
z=x+y;
}
void sub()
{
z=x-y;
}
void mul()
{
z=x*y;
}
void div()
{
z=x/y;
}
void mod()
{
z=x%y;
}
void preinc()
{
z=(++x);
}
void postinc()
{
z=(x++);
}
void predec()
{
z=(--x);
}
void postdec()
{
z=(x--);
}
void not(boolean x1)
{
z1=(!x1);
}
void pe()
{
z=(x+=y);
}
void se()
{
z=(x-=y);
}
void me()
{
z=(x*=y);
}
void de()
{
z=(x/=y);
}
void moe()
{
z=(x%=y);
}
void equalto()
{
if(x==y)
{
System.out.println("Numbers are equal");
}
else {
System.out.println("Numbers are not equal");
}
}
void notequalto()
{
if(x!=y)
{
System.out.println("Numbers are not equal");
}
else
{
System.out.println("Numbers are equal");
}
}
void less()
{
if(x<y)
{
System.out.println("First no is less than second number");
}
else {
System.out.println("First no is not less than or equal to second");
}
}
void lessequal()
{
if(x<=y)
{
System.out.println("First no is less than or equal to second number");
}
else {
System.out.println("First no is greater than second number");
}
}
void greater()
{
if(x>y)
{
System.out.println("First no is greater than second number");
}
else {
System.out.println("First no is not greater than or equal to second");
}
}
void greaterequal()
{
if(x>=y)
{
System.out.println("First no is greater than or equal to second number");
}
else {
System.out.println("First no is less than second number");
}
}
void and()
{
z1=(x1&&y1);
}
void or()
{
z1=(x1||y1);
}
void xor()
{
z1=(x1^y1);
}
void show()
{
System.out.println(z);
}
void show1()
{
System.out.println(z1);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
do
{
Scanner sc = new Scanner(System.in);
System.out.println("Ente Frist value");
x=sc.nextInt();
System.out.println("Ente Second value");
y=sc.nextInt();
System.out.println("Enter the choice");
String[][] b = {{"1=>Addition","2=>Substraction", "3=>Multiplication", "4=>Division", "5=>Modulus","6=>Pre-Increment"},{"7=>Post-Increment",
"8=>Pre-Decrement","9=>Post-Decrement","10=>Not","11=>Add and equal to","12=>Subtract equal to"},{"13=>multiply equal to",
"14=>Divide equal to","15=>Mod equal to","16=>Equal to","17=>Not Equal to","18=>Less than"},{"19=>Less than or equal to",
"20=>Greater than","21=>Greatere than or equal to","22=>Logical AND","23=>Logical OR","24=>logical XOR"}};
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
System.out.print(b[i][j]+"\t");
}
System.out.println();
}
// x1;
calculator c = new calculator(x,y,z);
//c.show();
System.out.println("Enter choice");
int a=sc.nextInt();
switch(a)
{
case 1:
c.add();
System.out.println("Addition is");
c.show();
break;
case 2:
c.sub();
System.out.println("Substrsction is");
c.show();
break;
case 3:
c.mul();
System.out.println("Multiplication is");
c.show();
break;
case 4:
c.div();
System.out.println("Division is");
c.show();
break;
case 5:
c.mod();
System.out.println("modulus is");
c.show();
break;
case 6:
c.preinc();
System.out.println("Pre increment is : ");
c.show();
break;
case 7:
c.postinc();
System.out.println("Post increment is : ");
c.show();
break;
case 8:
c.predec();
System.out.println("Pre decrement is : ");
c.show();
break;
case 9:
c.postdec();
System.out.println("Post decrement is : ");
c.show();
break;
case 10:
System.out.println("Enter boolean value");
x1=sc.nextBoolean();
c.not(x1);
System.out.println("Logical NOT is : ");
c.show();
break;
case 11:
c.pe();
System.out.println("plus equal to += is");
c.show();
break;
case 12:
c.se();
System.out.println("Substrsct equal to -= is");
c.show();
break;
case 13:
c.me();
System.out.println("Multiply equal to *= is");
c.show();
break;
case 14:
c.de();
System.out.println("Division equal to /= is");
c.show();
break;
case 15:
c.moe();
System.out.println("Modulus equal to %= is");
c.show();
break;
case 16:
c.equalto();
// System.out.println("Both vslues are equal");
// c.show();
break;
case 17:
c.notequalto();
// System.out.println("Both values are different");
//c.show();
break;
case 18:
c.less();
//System.out.println("First value is less than second");
//c.show();
break;
case 19:
c.lessequal();
//System.out.println("First value is less than or equal to second");
//c.show();
break;
case 20:
c.greater();
//System.out.println("First value is greater than second");
//c.show();
break;
case 21:
c.greaterequal();
//System.out.println("First value is greater than or equal to second");
//c.show();
break;
case 22:
System.out.println("Enter boolean value 1");
x1=sc.nextBoolean();
System.out.println("Enter boolean value 2");
y1=sc.nextBoolean();
c.and();
System.out.println("Logical AND is");
c.show1();
case 23:
System.out.println("Enter boolean value 1");
x1=sc.nextBoolean();
System.out.println("Enter boolean value 2");
y1=sc.nextBoolean();
c.or();
System.out.println("Logical OR is");
c.show1();
case 24:
System.out.println("Enter boolean value 1");
x1=sc.nextBoolean();
System.out.println("Enter boolean value 2");
y1=sc.nextBoolean();
c.xor();
System.out.println("Logical XOR is");
c.show1();
default:
System.out.println("Wrong input");
}
}
while(true);
}
}