Skip to content

Commit

Permalink
Merge pull request #97 from classskipper351/master
Browse files Browse the repository at this point in the history
Fixed a bug in the calculator and now forces you to re-enter an incorrectly formatted answer
  • Loading branch information
classskipper351 authored Apr 11, 2024
2 parents d063ff3 + 2c3a8e2 commit 0903df5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions recordList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
2024-04-10 15:37:53 0.11764705882352941 0.0 854452107 75-65,10.0 17/4,4.25 3/4,0.75 57/8,7.125 84*38,3192.0 79*92,7268.0 45+21,66.0 45*5,225.0 61-89,-28.0 62+68,130.0
2024-04-10 16:08:33 0.29411764705882354 0.4 1784552838 36+17,53.0 19+13,32.0 49/2,24.5 28+16,44.0 76+32,108.0 25*22,550.0 34+42,76.0 28-94,-66.0 0-72,-72.0 96/7,13.714285714285714
2024-04-10 16:19:08 0.20833333333333334 0.3 1784552838 53/6,8.833333333333334 1-71,-70.0 78-57,21.0 75-54,21.0 15/2,7.5 6+59,65.0 57+81,138.0 56+2,58.0 7-49,-42.0 33+87,120.0
2024-04-12 01:10:44 75.0 0.0 198423881 27/8,3.375 66+27,93.0 78+22,100.0 70-55,15.0 13*28,364.0 18+25,43.0 95-12,83.0 62-8,54.0 32+63,95.0 40-51,-11.0
3 changes: 2 additions & 1 deletion src/main/java/seedu/duke/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ private static ArrayList<Object> toSuffix(ArrayList<Object> formula) {
for (Object object : formula) {
if (object instanceof Integer) {
suffix.add(object);
} else if (object instanceof String op) {
} else if (object instanceof String ) {
String op = (String) object;

if (opStack.empty()) {
opStack.push(op);
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/seedu/duke/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,20 @@ void getUserAnswer() {
userInput = ui.readCommand();
userAnswer[i] = userInput;
double answer = Double.NEGATIVE_INFINITY;
try {
answer = Double.parseDouble(userInput);
} catch (NumberFormatException e) {
ui.print("Invalid Input, please enter a number");
wrongAnswer.add(userInput);
wrongProblem.add(problem);
continue;
boolean isValid = false;
while (!isValid) {

try {
answer = Double.parseDouble(userInput);
isValid = true;
} catch (NumberFormatException e) {
ui.print("Invalid Input, please enter a number");
//wrongAnswer.add(userInput);
//wrongProblem.add(problem);
//continue;
userInput = ui.readCommand();

}
}

if (checkCorrectness(problem, answer)) {
Expand Down

0 comments on commit 0903df5

Please sign in to comment.