Skip to content

Commit 80e6a1b

Browse files
committed
Update General_purpose_calc.java
1 parent cc71aa6 commit 80e6a1b

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

General_purpose_calc.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public static void main(String[] args)
2626
System.out.println(" - Press 2 if base and hypotenuse are given ");
2727
System.out.println(" - press 3 if height and hypotenuse are given ");
2828
double b, h, hp; // Declaring variables to be used in the following switch case
29-
int chp;
30-
chp = sc.nextInt();
29+
char chp;
30+
chp = sc.next().charAt(0);
3131
switch(chp)
3232
{
33-
case 1 :System.out.println(" > Enter the length of base ");
33+
case '1' :System.out.println(" > Enter the length of base ");
3434
b = sc.nextDouble();
3535
System.out.println(" > Enter the length of height ");
3636
h = sc.nextDouble();
@@ -39,7 +39,7 @@ public static void main(String[] args)
3939
double rhp = Math.sqrt(hp);
4040
System.out.println(" Solved Hypotenuse is --> " + rhp );
4141
break;
42-
case 2 :System.out.println(" > Enter the length of base ");
42+
case '2' :System.out.println(" > Enter the length of base ");
4343
b = sc.nextDouble();
4444
System.out.println(" > Enter the length of hypotenuse ");
4545
hp = sc.nextDouble();
@@ -49,7 +49,7 @@ public static void main(String[] args)
4949
rh = Math.sqrt(h);
5050
System.out.println(" Solved Height is --> " + rh );
5151
break;
52-
case 3 :System.out.println(" > Enter the length of height ");
52+
case '3' :System.out.println(" > Enter the length of height ");
5353
h = sc.nextDouble();
5454
System.out.println(" > Enter the length of hypotenuse ");
5555
hp = sc.nextDouble();
@@ -64,14 +64,14 @@ public static void main(String[] args)
6464
}
6565
else if(ch1 == '2') // This part gets executed if user enters "2"
6666
{
67-
int vnum;
67+
char vnum;
6868
System.out.println(" > Enter the number of terms ");
69-
vnum = sc.nextInt();
69+
vnum = sc.next().charAt(0);
7070
switch(vnum)
7171
{
72-
case 1 :System.out.println(" ERROR --> Number of terms can not be 1 <-- ");
72+
case '1' :System.out.println(" ERROR --> Number of terms can not be 1 <-- ");
7373
break;
74-
case 2 :double t1, t2, a1; // Always use double type for making any kind of calculator as int does not allow use of decimals, and gives a type miss match error when a decimal term is entered
74+
case '2' :double t1, t2, a1; // Always use double type for making any kind of calculator as int does not allow use of decimals, and gives a type miss match error when a decimal term is entered
7575
System.out.println(" > Enter the value of the first term ");
7676
t1 = sc.nextDouble();
7777
System.out.println(" > Enter the value of the second term ");
@@ -104,7 +104,7 @@ else if(tas == 4)
104104
System.out.println(" Your answer is --> " + a1 );
105105
}
106106
break;
107-
case 3:double t13, t23, t33;
107+
case '3': double t13, t23, t33;
108108
System.out.println(" > Enter the value of the first term ");
109109
t13 = sc.nextDouble();
110110
System.out.println(" > Enter the value of the second term ");
@@ -143,7 +143,7 @@ else if(tas3 == 4)
143143
System.out.println(" ERROR --> Unkown choice <-- ");
144144
}
145145
break;
146-
case 4:double t134, t234, t334, t434;
146+
case '4':double t134, t234, t334, t434;
147147
System.out.println(" > Enter the value of first term ");
148148
t134 = sc.nextDouble();
149149
System.out.println(" > Enter the value of second term ");
@@ -180,7 +180,7 @@ else if(tas34 == 4)
180180
System.out.println(" Your answer is --> " + a1 );
181181
}
182182
break;
183-
case 5:double t1345, t2345, t3345, t4345, t5345;
183+
case '5':double t1345, t2345, t3345, t4345, t5345;
184184
System.out.println(" > Enter the value of first term ");
185185
t1345 = sc.nextDouble();
186186
System.out.println(" > Enter the value of second term ");
@@ -258,28 +258,28 @@ else if(sp < cp)
258258
}
259259
else if(ch1 == '5') // This part gets executed when user enters "5"
260260
{
261-
int chA;
261+
char chA;
262262
System.out.println(" - Press '1' to calculate the Area of a square ");
263263
System.out.println(" - Press '2' to calculate the Area of a rectangle ");
264264
System.out.println(" - Press '3' to calculate the Area of a circle ");
265-
chA = sc.nextInt();
265+
chA = sc.next().charAt(0);
266266
switch(chA)
267267
{
268-
case 1 :double ss;
268+
case '1' :double ss;
269269
System.out.println(" > Enter the value of side ");
270270
ss = sc.nextDouble();
271271
double ssA = ss * ss;
272272
System.out.println(" Your answer is --> " + ssA );
273273
break;
274-
case 2 :double rl, rb;
274+
case '2' :double rl, rb;
275275
System.out.println(" > Enter the value of breadth (width) ");
276276
rb = sc.nextDouble();
277277
System.out.println(" > Enter the value of length ");
278278
rl = sc.nextDouble();
279279
double rA = rb * rl;
280280
System.out.println(" Your answer is --> " + rA );
281281
break;
282-
case 3 :double cr; // Once again using double for more accurate values
282+
case '3' :double cr; // Once again using double for more accurate values
283283
System.out.println(" Enter the value of radius ");
284284
cr = sc.nextDouble();
285285
double crX = 3.14159 * (cr * cr); // Defining PI to 5 decimals for even more accurate values
@@ -290,28 +290,28 @@ else if(ch1 == '5') // This part gets executed when user enters "5"
290290
}
291291
else if(ch1 == '6')
292292
{
293-
int chP;
293+
char chP;
294294
System.out.println(" - Press '1' to calculate the Perimeter of a square ");
295295
System.out.println(" - Press '2' to calculate the Perimeter of a rectangle ");
296296
System.out.println(" - Press '3' to calculate the Perimeter of a circle ");
297-
chP = sc.nextInt();
297+
chP = sc.next().charAt(0);
298298
switch(chP)
299299
{
300-
case 1 :double sP;
300+
case '1' :double sP;
301301
System.out.println(" > Enter value of side ");
302302
sP = sc.nextDouble();
303303
double sPA = (4 * sP);
304304
System.out.println(" Your answer is --> " + sPA );
305305
break;
306-
case 2 :double rPL, rPB;
306+
case '2' :double rPL, rPB;
307307
System.out.println(" > Enter value of breadth (width) ");
308308
rPB = sc.nextDouble();
309309
System.out.println(" > Enter value of length ");
310310
rPL = sc.nextDouble();
311311
double rPA = 2 * (rPL + rPB);
312312
System.out.println(" Your answer is --> " + rPA );
313313
break;
314-
case 3 :double crP;
314+
case '3' :double crP;
315315
System.out.println(" > Enter value of radius ");
316316
crP = sc.nextDouble();
317317
double crPA = 2 * 3.14159 * crP;

0 commit comments

Comments
 (0)