Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/classskipper351/tp
Browse files Browse the repository at this point in the history
  • Loading branch information
classskipper351 committed Apr 15, 2024
2 parents b31169b + c08e0fc commit 7a5a52d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/main/java/seedu/duke/DIYProblemSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;

public class DIYProblemSet {
ArrayList<Problem> problemSet;
Expand All @@ -12,7 +11,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 +19,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 7a5a52d

Please sign in to comment.