Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
A1WAYSD committed Sep 13, 2023
1 parent 8f8e7fe commit ad1f4af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package duke;

import duke.gui.MainWindow;
import duke.task.TaskList;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.io.FileNotFoundException;
Expand All @@ -12,12 +10,12 @@
* Represents an intelligent chat robot that helps a person to keep track of various things with encouraging quotes.
*/
public class Duke {
private static final String SAVING_ERROR_MSG = "⚠ Oops! Something wrong when closing:(";
private static final String BYE_MSG = "Bye!\n\"Beware the barrenness of a busy life.\"";
private Parser parser;
private Storage storage;
private TaskList tasks;
private Stage stage;
public String SAVING_ERROR_MSG = "⚠ Oops! Something wrong when closing:(";
public String BYE_MSG = "Bye!\n\"Beware the barrenness of a busy life.\"";

/**
* Initializes the chat robot. Establishes task list and parser.
Expand Down Expand Up @@ -50,7 +48,7 @@ public String getResponse(String input) {
}
}

public void close(){
public void close() {
this.stage.close();
}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/duke/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* Controller for MainWindow. Provides the layout for the other controls.
*/
public class MainWindow extends AnchorPane {
private static final String WELCOME_MSG = "Hi! This is your intelligent friend L.\n\"Dream big.\"\n"
+ "What can I do for you today?";
private static final String BYE_MSG = "Bye!\n\"Beware the barrenness of a busy life.\"";
@FXML
private ScrollPane scrollPane;
@FXML
Expand All @@ -26,9 +29,10 @@ public class MainWindow extends AnchorPane {
private Duke duke;
private Image userImage = new Image(this.getClass().getResourceAsStream("/images/DaUser.jpg"));
private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/DaDuke.jpg"));
private String WELCOME_MSG = "Hi! This is your intelligent friend L.\n\"Dream big.\"\n"
+ "What can I do for you today?";

/**
* Initializes the main window.
*/
@FXML
public void initialize() {
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
Expand All @@ -54,7 +58,7 @@ private void handleUserInput() {
DialogBox.getDukeDialog(response, dukeImage)
);
userInput.clear();
if (response.equals(duke.BYE_MSG)){
if (response.equals(BYE_MSG)) {
// Close the window after 5 seconds
PauseTransition pause = new PauseTransition(Duration.seconds(5));
pause.setOnFinished(event -> duke.close());
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/duke/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
public class ParserTest {

@Test
public void parse_bye_success() throws DukeException{
public void parse_bye_success() throws DukeException {
assertEquals("", new Parser(null).parse("88"));
}
@Test
public void parse_undefinedInput_exceptionThrown() {
try{
assertEquals("⚠ Sorry! I am not able to understand you. Try another language:D", new Parser(null).parse("undefined"));
try {
assertEquals("⚠ Sorry! I am not able to understand you. Try another language:D",
new Parser(null).parse("undefined"));
fail();
} catch (DukeException e) {
assertEquals("undefined", e.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/duke/task/TaskListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TaskListTest {
@Test
public void markTask_negativeIndex_exceptionThrown() {
try {
assertEquals("⚠ OOPS!!! The task index is out of range.", new TaskList().markTask(-1,true));
assertEquals("⚠ OOPS!!! The task index is out of range.", new TaskList().markTask(-1, true));
fail();
} catch (Exception e) {
assertEquals("task not found", e.getMessage());
Expand Down

0 comments on commit ad1f4af

Please sign in to comment.