From 452c8cb159f72869e131bcac99bbe9361d0681cb Mon Sep 17 00:00:00 2001 From: Zong Xian Date: Tue, 13 Sep 2022 23:48:48 +0800 Subject: [PATCH] Ceated Jar File --- build.gradle | 7 +++++- src/main/duke.txt | 2 -- src/main/java/duke/DialogBox.java | 3 ++- src/main/java/duke/Duke.java | 33 ++++++++++++++++++---------- src/main/java/duke/Launcher.java | 3 ++- src/main/java/duke/Main.java | 3 +++ src/main/java/duke/MainWindow.java | 16 ++++++++++---- src/main/java/duke/Storage.java | 13 ++++++----- src/main/java/duke/Ui.java | 4 +++- src/test/java/duke/DeadlineTest.java | 9 +++++--- 10 files changed, 63 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index 785f1f90bd..c0def11cbf 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,12 @@ repositories { } dependencies { + + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0' + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0' + String javaFxVersion = '11' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' @@ -43,7 +48,7 @@ test { } application { - mainClassName = "duke.Duke" + mainClassName = "duke.Launcher" } shadowJar { diff --git a/src/main/duke.txt b/src/main/duke.txt index 94b71f8dc5..e69de29bb2 100644 --- a/src/main/duke.txt +++ b/src/main/duke.txt @@ -1,2 +0,0 @@ -[E][] project meeting (at: Mon 2-4pm) -[D][] return book (by: 2019-12-02 2/12/2019 1800) diff --git a/src/main/java/duke/DialogBox.java b/src/main/java/duke/DialogBox.java index d183f8252b..00b00890a9 100644 --- a/src/main/java/duke/DialogBox.java +++ b/src/main/java/duke/DialogBox.java @@ -58,4 +58,5 @@ public static DialogBox getDukeDialog(String text, Image img) { db.flip(); return db; } -} \ No newline at end of file + +} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 481e60c52c..b6f45af116 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,21 +1,22 @@ package duke; +import java.io.IOException; +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; + import javafx.application.Application; -import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextField; -import javafx.scene.layout.*; -import javafx.stage.Stage; -import javafx.scene.control.Label; import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Region; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + -import java.awt.*; -import java.io.IOException; -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; /** * This class is responsible for the bot Duke @@ -25,7 +26,7 @@ public class Duke extends Application { // Attributes of a Duke object - private static final String FILEDESTINATION = "./src/main/duke.txt"; + private static final String FILEDESTINATION = "./duke.txt"; private Ui ui; private Storage storage; private TaskList taskList; @@ -42,7 +43,7 @@ public class Duke extends Application { /** * The constructor for the Duke class */ - public Duke() { + public Duke() throws IOException { ui = new Ui(); storage = new Storage(FILEDESTINATION); taskList = new TaskList(); @@ -161,6 +162,8 @@ protected String getResponse(String input) throws IOException { String userCommand = input; if (userCommand.equals("bye")) { return ui.bye(); + } else if (userCommand.equals("hello")) { + return ui.greet(); } else if (userCommand.equals("list")) { return ui.showTaskList(); } else { @@ -340,6 +343,12 @@ public void run() throws DukeException, IOException { } } + /** + * Find matching tasks from the keywords + * @param taskArrayList the list of all the tasks + * @param keywords the keywords that the user entered + * @return the string listing all the tasks that match the keywords + */ public String findMatchingTasksFromKeywords(List taskArrayList, String keywords) { String outputString = ""; outputString += "Here are the matching tasks in your list:\n"; diff --git a/src/main/java/duke/Launcher.java b/src/main/java/duke/Launcher.java index 5483e63637..446ed264ed 100644 --- a/src/main/java/duke/Launcher.java +++ b/src/main/java/duke/Launcher.java @@ -9,4 +9,5 @@ public class Launcher { public static void main(String[] args) { Application.launch(Main.class, args); } -} \ No newline at end of file + +} diff --git a/src/main/java/duke/Main.java b/src/main/java/duke/Main.java index db593707b5..6b941e4453 100644 --- a/src/main/java/duke/Main.java +++ b/src/main/java/duke/Main.java @@ -15,6 +15,9 @@ public class Main extends Application { private Duke duke = new Duke(); + public Main() throws IOException { + } + @Override public void start(Stage stage) { try { diff --git a/src/main/java/duke/MainWindow.java b/src/main/java/duke/MainWindow.java index 0fc43f291a..92707f8d23 100644 --- a/src/main/java/duke/MainWindow.java +++ b/src/main/java/duke/MainWindow.java @@ -1,15 +1,20 @@ package duke; +import java.awt.Color; +import java.io.IOException; + import javafx.fxml.FXML; import javafx.geometry.Insets; import javafx.scene.control.Button; import javafx.scene.control.ScrollPane; import javafx.scene.control.TextField; import javafx.scene.image.Image; -import javafx.scene.layout.*; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; +import javafx.scene.layout.VBox; -import java.awt.*; -import java.io.IOException; /** * Controller for MainWindow. Provides the layout for the other controls. @@ -29,12 +34,15 @@ public class MainWindow extends AnchorPane { private Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png")); private Image dukeImage = new Image(this.getClass().getResourceAsStream("/images/user2.png")); + /** + * Initialise the window + */ @FXML public void initialize() { scrollPane.vvalueProperty().bind(dialogContainer.heightProperty()); // Generate the background colour for the Dialog - java.awt.Color awtColor = Color.cyan ; + java.awt.Color awtColor = Color.cyan; int r = awtColor.getRed(); int g = awtColor.getGreen(); int b = awtColor.getBlue(); diff --git a/src/main/java/duke/Storage.java b/src/main/java/duke/Storage.java index 5d67679e01..bb8184abd6 100644 --- a/src/main/java/duke/Storage.java +++ b/src/main/java/duke/Storage.java @@ -1,9 +1,6 @@ package duke; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.time.LocalDate; import java.util.Arrays; import java.util.List; @@ -21,8 +18,14 @@ public class Storage { * Constructor for the Storage class * @param fileDestination the destination filepath of the file */ - public Storage(String fileDestination) { + public Storage(String fileDestination) throws IOException { this.fileDestination = fileDestination; + File file = new File(fileDestination); + if (file.exists()) { + return; + } + file.getParentFile().mkdirs(); + file.createNewFile(); } /** diff --git a/src/main/java/duke/Ui.java b/src/main/java/duke/Ui.java index 6f6e0207f7..2579f8dcd0 100644 --- a/src/main/java/duke/Ui.java +++ b/src/main/java/duke/Ui.java @@ -27,7 +27,9 @@ public Ui() { /** * Greets the user */ - public String greet() { return GREETING;} + public String greet() { + return GREETING; + } /** * Say bye to the user diff --git a/src/test/java/duke/DeadlineTest.java b/src/test/java/duke/DeadlineTest.java index d2ab97a554..611325a487 100644 --- a/src/test/java/duke/DeadlineTest.java +++ b/src/test/java/duke/DeadlineTest.java @@ -1,15 +1,18 @@ package duke; -import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; + import java.time.LocalDate; +import org.junit.jupiter.api.Test; + + public class DeadlineTest { @Test public void toStringTest() throws DukeException { LocalDate by = LocalDate.parse("2019-12-02"); - Deadline newDeadline = new Deadline("Deadline", by, "1800" ); + Deadline newDeadline = new Deadline("Deadline", by, "1800"); assertEquals("[D][] Deadline (by: 2019-12-02 1800)", newDeadline.toString()); } @@ -20,4 +23,4 @@ public void anotherToStringTest() throws DukeException { assertEquals("[D][] Deadline (by: 2022-08-15 2300)", newDeadline.toString()); } -} \ No newline at end of file +}