-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathImprovisedCalculator.java
171 lines (167 loc) · 4.27 KB
/
ImprovisedCalculator.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
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
import java.util.*;
import java.lang.*;
class Calculator
{
static Scanner st = new Scanner(System.in);
static int firstno, secondno;
public static void add()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
System.out.println("Enter the second number");
secondno= st.nextInt();
int sum;
sum=firstno+secondno;
System.out.println("The sum of two numbers"+sum);
}
public static void subtract()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
System.out.println("Enter the second number");
secondno= st.nextInt();
int difference;
difference =firstno-secondno;
System.out.println("The difference of two numbers"+difference);
}
public static void multiply()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
System.out.println("Enter the second number");
secondno= st.nextInt();
int product;
product=firstno*secondno;
System.out.println("The product of two numbers"+product);
}
public static void division()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
System.out.println("Enter the second number");
secondno= st.nextInt();
double quotient;
quotient=((double)firstno/secondno);
System.out.println("The division of two numbers"+quotient);
}
public static void percent()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
double percent;
percent=((double)firstno/100);
System.out.println("The percent of a number"+percent);
}
public static void square()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
double square;
square=firstno*firstno;
System.out.println("The square of a number"+square);
}
public static void cube()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
double cube;
cube=firstno*firstno*firstno;
System.out.println("The cube of a number"+cube);
}
public static void power()
{
System.out.println("Enter the first number");
firstno= st.nextInt();
System.out.println("Enter the second number");
secondno= st.nextInt();
double power;
power = Math.pow(firstno, secondno);
System.out.println("The power of two numbers"+power);
}
public static void round()
{
System.out.println("Enter the first number");
double input;
input=st.nextDouble();
double rounded;
rounded = Math.round(input);
System.out.println(rounded);
}
public static void floor()
{
System.out.println("Enter the first number");
double input;
input=st.nextDouble();
double floorno;
floorno = Math.floor(input);
System.out.println("The floor of a number"+floorno);
}
public static void ceil()
{
System.out.println("Enter the first number");
double input;
input=st.nextDouble();
double ceilno;
ceilno = Math.ceil(input);
System.out.println("The ceil of a number"+ceilno);
}
}
public class Calci {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
Calculator obj = new Calculator();
System.out.println("Enter any digit between 1-9");
while(sc.nextInt()!=0){
System.out.println("Enter desired character");
char ch;
ch=sc.next().charAt(0);
switch(ch)
{
case 'a':{
obj.add();
break;
}
case 's':{
obj.subtract();
break;
}
case 'm':{
obj.multiply();
break;
}
case 'd':{
obj.division();
break;
}
case 'p':{
obj.percent();
break;
}
case 'q':{
obj.square();
break;
}
case 'u':{
obj.cube();
break;
}
case 'w':{
obj.power();
break;
}
case 'r':{
obj.round();
break;
}
case 'f':{
obj.floor();
break;
}
case 'c':{
obj.ceil();
break;
}
}
}
}
}