Skip to content

Commit

Permalink
Improve code readability
Browse files Browse the repository at this point in the history
Break up lines in DialogBox class.

Introduce more intermediate variables to improve readability and
explicitness of code in Parser and Storage classes.
  • Loading branch information
szelongq committed Sep 8, 2021
1 parent d03c6ee commit 8b8c55c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/main/java/duke/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

/**
* An example of a custom control using FXML.
* This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label
* containing text from the speaker.
* This control represents a dialog box consisting of an ImageView
* to represent the speaker's face and a label containing text
* from the speaker.
*/
public class DialogBox extends HBox {
@FXML
Expand All @@ -27,7 +28,8 @@ public class DialogBox extends HBox {

private DialogBox(String text, Image img) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
FXMLLoader fxmlLoader = new FXMLLoader(
MainWindow.class.getResource("/view/DialogBox.fxml"));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
fxmlLoader.load();
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,22 @@ public static Task parseNewTask(String userInput) throws MissingInputException {

switch (taskType) {
case TODO:
return new ToDo(userInputScanner.nextLine().trim());
String todoName = userInputScanner.nextLine().trim();
return new ToDo(todoName);
case DEADLINE:
userInputScanner.useDelimiter(" /by ");
return new Deadline(userInputScanner.next().trim(),
LocalDate.parse(userInputScanner.next().trim()));
String deadlineName = userInputScanner.next().trim();
LocalDate deadlineDateTime =
LocalDate.parse(userInputScanner.next().trim());

return new Deadline(deadlineName, deadlineDateTime);
case EVENT:
userInputScanner.useDelimiter(" /at ");
return new Event(userInputScanner.next().trim(),
LocalDate.parse(userInputScanner.next().trim()));
String eventName = userInputScanner.next().trim();
LocalDate eventDateTime =
LocalDate.parse(userInputScanner.next().trim());

return new Event(eventName, eventDateTime);
default:
return null; // Error
}
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ private ArrayList<Task> loadTasks(Path savePath) {
try (BufferedReader reader = Files.newBufferedReader(savePath)) {

ArrayList<Task> tasks = new ArrayList<>();
String line = null;
String line = reader.readLine();

while ((line = reader.readLine()) != null) {
while (line != null) {
tasks.add(loadTask(line));
line = reader.readLine();
}

return tasks;
Expand All @@ -76,18 +77,18 @@ private Task loadTask(String savedTask) {

switch (taskType) {
case "T":
loadedTask = new ToDo(taskDesc, isTaskDone));
loadedTask = new ToDo(taskDesc, isTaskDone);
break;
case "D":
loadedTask = new Deadline(taskDesc,
LocalDate.parse(saveDataScanner.next()), isTaskDone);
LocalDate deadlineDateTime = LocalDate.parse(saveDataScanner.next());
loadedTask = new Deadline(taskDesc, deadlineDateTime, isTaskDone);
break;
case "E":
loadedTask = new Event(taskDesc,
LocalDate.parse(saveDataScanner.next()), isTaskDone);
LocalDate eventDateTime = LocalDate.parse(saveDataScanner.next());
loadedTask = new Event(taskDesc, eventDateTime, isTaskDone);
break;
default:
break; //Error
break; // Error
}
saveDataScanner.close();

Expand Down

0 comments on commit 8b8c55c

Please sign in to comment.