Scientific Calculator
Scientific Calculator
This program is designed to act like a “Scientific calculator” with the usual standard functions (add, subtract, multiply, divide, modulus). Also, the calculator will have the capability of performing functions in binary (base 2), octal (base 8) and hexadecimal (base 16), in addition to the usual decimal (base 10). On the other head the calculator will have the capability of performing trigonometric functions in (sin), (sinh), (cos), (cosh), (tan), (tanh).
Using Software Tools:
NetBeans IDE 8.2
Stype-1
Create CalculatorView.java class
Copy below link and paste it new tab
https://drive.google.com/file/d/1tUH8GrS7DVcANWed4iuajpyhxfbmOk3n/view?usp=sharing
Copy the code and paste it between the CalculatorView.java class.
Stype-2
Create CalculatorModel.java class
Copy the below code and paste it between the CalculatorModel.java class.
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 | public class CalculatorModel { int operator = 0; double operand1; double operand2; double result; public void setOperand(String opr) { if (!opr.equals("")) { double num = Double.valueOf(opr); if (num <= 100000000 && num >= -100000000) { if (operator == 0) { operand1 = num; } else { operand2 = num; } } } } public void setOperator(int operator) { this.operator = operator; } public double getResult() { return result; } public void setResult(double result) { this.result = result; } public void process() { switch (operator) { case 1: result = summation(operand1, operand2); break; case 2: result = subtraction(operand1, operand2); break; case 3: result = multiplication(operand1, operand2); break; case 4: result = division(operand1, operand2); break; case 5: result = modulus(operand1, operand2); break; case 6: result = inverse(operand1); break; case 7: result = sin(operand1); break; case 8: result = yrootx(operand1, operand2); break; case 9: result = raised3(operand1); break; case 10: result = log(operand1); break; case 11: result = Degrees(operand1); break; case 12: result = cos(operand1); ; break; case 13: result = tan(operand1); ; break; case 14: result = bXraisedToY(operand1, operand2); break; case 15: result = exp(operand1); break; case 16: result = sinh(operand1); ; break; case 17: result = cosh(operand1); ; break; case 18: result = tanh(operand1); ; break; case 19: result = sqrt(operand1); break; case 20: result = PI(); break; case 21: result = raised2(operand1); break; case 23: result = fact(operand1); break; } operand1 = result; } public double summation(double a, double b) { result = a + b; return result; } public double subtraction(double a, double b) { result = a - b; return result; } public double multiplication(double a, double b) { result = a * b; return result; } public double division(double a, double b) { result = a / b; return result; } public double modulus(double a, double b) { result = a % b; return result; } public double inverse(double a) { result = 1 / a; return result; } public double sin(double a) { result = Math.sin(Math.toRadians(a)); return result; } public double cos(double a) { result = Math.cos(Math.toRadians(a)); return result; } public double tan(double a) { result = Math.tan(Math.toRadians(a)); return result; } public double sinh(double a) { result = Math.sinh(Math.toRadians(a)); return result; } public double cosh(double a) { result = Math.cosh(Math.toRadians(a)); return result; } public double tanh(double a) { result = Math.tanh(Math.toRadians(a)); return result; } public double yrootx(double a, double b) { result = Math.pow(a, (1 / b)); return result; } public double raised3(double a) { result = a * a * a; return result; } public double bXraisedToY(double a, double b) { result = 1.0; while (b > 0) { if (b % 2 == 0) { a = a * a; b = b / 2; } else { result = result * a; b = b - 1; } } return result; } public double exp(double a) { result = Math.exp(a); return result; } public double log(double a) { result = Math.log(a); return result; } public double Degrees(double a) { result = Math.toDegrees(a); return result; } public double sqrt(double a) { double t; result = a / 2; do { t = result; result = (t + (a / t)) / 2; } while ((t - result) != 0); return result; } public double PI() { result = Math.PI; return result; } public double raised2(double a) { result = a * a; return result; } public double fact(double a) { double f = a; double n = 1; while (f != 0) { n = n * f; f--; } result = n; return result; } } |
Stype-3
Create MainMethod.java class
Copy the below code and paste it between the MainMethod.java class.
1 2 3 4 5 6 7 | public class MainMethod { public static void main(String[] args) { new CalculatorView().setVisible(true); } } |