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

solve the infinite loop, replace scanner by ui.readcommand #114

Merged
merged 5 commits into from
Apr 15, 2024
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
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();
}


}
Loading