Skip to content

Commit

Permalink
Merge pull request #114 from Celineyaa/master
Browse files Browse the repository at this point in the history
solve the infinite loop, replace scanner by ui.readcommand
  • Loading branch information
Celineyaa authored Apr 15, 2024
2 parents 4a871e8 + c969593 commit 07ae11f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Empty file added recordList.txt
Empty file.
16 changes: 6 additions & 10 deletions src/main/java/seedu/duke/DIYProblemSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public DIYProblemSet() {
}

public void addDIYProblemSet(Ui ui) {
Scanner scanner = new Scanner(System.in);
ui.print("Please input your DIY problemSet: ");
String description;
String correctAnswer;
Expand All @@ -21,37 +20,34 @@ public void addDIYProblemSet(Ui ui) {
String quit = "";
while (!quit.equals("y")) {
ui.print("input the description of the problem (e.g. 1+2*3): ");
description = scanner.nextLine();
description = ui.readCommand();
ui.print("input the correct answer of the problem (e.g. 7): ");
correctAnswer = scanner.nextLine();
correctAnswer = ui.readCommand();
boolean isValidAnswer = false;
while (!isValidAnswer) {
try {
answer = Double.parseDouble(correctAnswer);
isValidAnswer = true;
} catch (NumberFormatException e) {
ui.print("Invalid answer! Please input a number.");
correctAnswer = scanner.nextLine();
correctAnswer = ui.readCommand();
}
}
ui.print("Input the explanations of the problem (e.g. 1+2*3=7): ");
explanations = scanner.nextLine();
explanations = ui.readCommand();
Problem problem = new Problem(description,answer,explanations);
problemSet.add(problem);
ui.print("Have you finished adding problems? y/n: ");
quit = scanner.nextLine();
quit = ui.readCommand();
while (!quit.equals("y") && !quit.equals("n")) {
ui.print("input is invalid! Please input 'y' or 'n': ");
quit = scanner.nextLine();
quit = ui.readCommand();
}
}
Record record = new Record(LocalDateTime.now(), 0.0, 0.0, problemSet, ProblemSetType.USER_DIY.getValue());
Storage.addRecord(record);
ui.print("Record successfully saved!");
record.print(true);
Ui.showLine();
scanner.close();
}


}

0 comments on commit 07ae11f

Please sign in to comment.