Skip to content

Commit

Permalink
Merge pull request #104 from Shuvamdt/master
Browse files Browse the repository at this point in the history
Fixed bug using .equals()
  • Loading branch information
pH-7 authored Feb 6, 2024
2 parents ded4ad9 + a5fc3db commit 36c3c14
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/simplejavacalculator/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ public enum MonoOperatorModes {
private BiOperatorModes mode = BiOperatorModes.normal;

private Double calculateBiImpl() {
if (mode == BiOperatorModes.normal) {
if (mode.equals(BiOperatorModes.normal)) {
return num2;
}
if (mode == BiOperatorModes.add) {
if (mode.equals(BiOperatorModes.add)) {
if (num2 != 0) {
return num1 + num2;
}

return num1;
}
if (mode == BiOperatorModes.minus) {
if (mode.equals(BiOperatorModes.minus)) {
return num1 - num2;
}
if (mode == BiOperatorModes.multiply) {
if (mode.equals(BiOperatorModes.multiply)) {
return num1 * num2;
}
if (mode == BiOperatorModes.divide) {
if (mode.equals(BiOperatorModes.divide)) {
return num1 / num2;
}
if (mode == BiOperatorModes.xpowerofy) {
if (mode.equals(BiOperatorModes.xpowerofy)) {
return pow(num1,num2);
}

Expand All @@ -58,7 +58,7 @@ private Double calculateBiImpl() {
}

public Double calculateBi(BiOperatorModes newMode, Double num) {
if (mode == BiOperatorModes.normal) {
if (mode.equals(BiOperatorModes.normal)) {
num2 = 0.0;
num1 = num;
mode = newMode;
Expand All @@ -85,41 +85,41 @@ public Double reset() {


public Double calculateMono(MonoOperatorModes newMode, Double num) {
if (newMode == MonoOperatorModes.square) {
if (newMode.equals(MonoOperatorModes.square)) {
return num * num;
}
if (newMode == MonoOperatorModes.squareRoot) {
if (newMode.equals(MonoOperatorModes.squareRoot)) {
return Math.sqrt(num);
}
if (newMode == MonoOperatorModes.oneDividedBy) {
if (newMode.equals(MonoOperatorModes.oneDividedBy)) {
return 1 / num;
}
if (newMode == MonoOperatorModes.cos) {
if (newMode.equals(MonoOperatorModes.cos)) {
return Math.cos(Math.toRadians(num));
}
if (newMode == MonoOperatorModes.sin) {
if (newMode.equals(MonoOperatorModes.sin)) {
return Math.sin(Math.toRadians(num));
}
if (newMode == MonoOperatorModes.tan) {
if (num == 0 || num % 180 == 0) {
if (newMode.equals(MonoOperatorModes.tan)) {
if (num == 0 || num % 180 == 0 ) {
return 0.0;
}
if (num % 90 == 0 && num % 180 != 0) {
if (num % 90 == 0.0 && num % 180 != 0.0) {
return NaN;
}

return Math.tan(Math.toRadians(num));
}
if (newMode == MonoOperatorModes.log) {
if (newMode.equals(MonoOperatorModes.log)) {
return log10(num);
}
if (newMode == MonoOperatorModes.ln) {
if (newMode.equals(MonoOperatorModes.ln)) {
return log(num);
}
if (newMode == MonoOperatorModes.rate) {
return num / 100;
if (newMode.equals(MonoOperatorModes.rate) ) {
return num / 100;
}
if (newMode == MonoOperatorModes.abs){
if (newMode.equals(MonoOperatorModes.abs)){
return Math.abs(num);
}

Expand All @@ -128,3 +128,4 @@ public Double calculateMono(MonoOperatorModes newMode, Double num) {
}

}

0 comments on commit 36c3c14

Please sign in to comment.