Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in the calculator and now forces you to re-enter an incorrectly formatted answer #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading