Skip to content

Commit

Permalink
Merge branch 'Improve-code'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiWei1010 committed Feb 26, 2024
2 parents ee1771a + 8cf5b98 commit 453ee95
Show file tree
Hide file tree
Showing 26 changed files with 549 additions and 308 deletions.
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ test {
}

application {
mainClass.set("seedu.duke.Duke")
mainClassName = "homie.Launcher"
}

shadowJar {
mainClassName = 'seedu.duke.Main'
archiveBaseName = "duke"
archiveClassifier = null
archiveFileName = 'duke.jar'
dependsOn("distZip", "distTar")
archiveFileName = 'homie.jar'
}

run{
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/homie/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
package homie;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Deadline class that extends the Task class.
* Can specify the Local Date Time to keep track of
* when to complete deadline by.
* The Deadline class that extends the Task class. Handles all deadline related tasks.
* Can specify the Local Date Time to keep track of when to complete deadline by.
*/
public class Deadline extends Task {
public class Deadline extends Task implements Serializable {

protected LocalDateTime by;
protected LocalDateTime dueDateTime;

/**
* Constructor for Deadline class
* @param description For the deadline task
* @param by This is the Local Date Time to complete the deadline by
* Constructor for Deadline class to create a new deadline instance.
*
* @param description The description of deadline task.
* @param by This is the Local Date Time to complete the deadline by.
*/
public Deadline(String description, String by) {
super(description);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MM yyyy HHmm");
this.by = LocalDateTime.parse(by, formatter);
this.dueDateTime = LocalDateTime.parse(by, DateTimeFormatter.ofPattern("dd MM yyyy HHmm"));
}

@Override
public String toString() {
return "[D][" + this.getStatusIcon() + "] " + super.toString() + " (by: "
+ by.format(DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm")) + ")";
+ this.dueDateTime.format(DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm")) + ")";
}
}
17 changes: 17 additions & 0 deletions src/main/java/homie/DeadlineException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package homie;

/**
* Deadline exception class. Handles all exceptions related to Deadline class.
* Thrown when no description for deadline task is given, or format of due date is wrong.
*/
public class DeadlineException extends Exception {
/**
* Constructor for DeadlineException class.
*
* @param message The error message.
*/
public DeadlineException(String message) {
super("Bruh... " + message + "\nPlease follow the format:\ndeadline "
+ "{DEADLINE_DESCRIPTION} /by {dd MM yyyy HHmm}");
}
}
16 changes: 16 additions & 0 deletions src/main/java/homie/DeleteException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package homie;

/**
* Delete exception class. Handles all exceptions related to Delete command.
* Thrown when no index is given, or index is out of range.
*/
public class DeleteException extends Exception {
/**
* Constructor for DeleteException class.
*
* @param message The error message.
*/
public DeleteException(String message) {
super("Bruh... " + message + "\nPlease follow the format: \ndelete {INDEX}");
}
}
29 changes: 18 additions & 11 deletions src/main/java/homie/Event.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package homie;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Event class that extends Task class.
* Can specify event starts from when and when the events end.
* Event class that extends Task class. Handles all event related tasks.
* Can specify event starting date time and ending date time.
*/
public class Event extends Task {

protected String from;
protected String to;
protected LocalDateTime startDateTime;
protected LocalDateTime endDateTime;

/**
* Constructor for Event class
* @param description For the Event Task.
* @param from This is to keep track when the event starts
* @param to This is to keep track when the event ends
*
* @param description The description of the event task.
* @param start The start date time of event task in String, of 'dd MM yyyy HHmm' format
* @param end The end date time of event task in String, of 'dd MM yyyy HHmm' format
*/
public Event(String description, String from, String to) {
public Event(String description, String start, String end) {
super(description);
this.from = from;
this.to = to;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MM yyyy HHmm");
this.startDateTime = LocalDateTime.parse(start, formatter);
this.endDateTime = LocalDateTime.parse(end, formatter);
}

@Override
public String toString() {
return "[E][" + this.getStatusIcon() + "] " + super.toString() + " (from: " + from + " to: " + to + ")";
return "[E][" + this.getStatusIcon() + "] " + super.toString() + " (from: "
+ this.startDateTime.format(DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm")) + " to: "
+ this.endDateTime.format(DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm")) + ")";
}
}
17 changes: 17 additions & 0 deletions src/main/java/homie/EventException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package homie;

/**
* Event exception class. Handles all exceptions related to Event Class.
* Thrown when no description of event is given, or start date or end date is of incorrect format.
*/
public class EventException extends Exception {
/**
* Constructor for EventException class.
*
* @param message The error message.
*/
public EventException(String message) {
super("Bruh... " + message + "\nPlease follow the format:\n event {EVENT_DESCRIPTION} "
+ "/from {dd MM yyyy HHmm} /to {dd MM yyyy HHmm}");
}
}
16 changes: 16 additions & 0 deletions src/main/java/homie/FindException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package homie;

/**
* Find exception class. Handles all exceptions related to Find command.
* Thrown when no keyword is given, or keyword is more than one word.
*/
public class FindException extends Exception {
/**
* Constructor for MarkException class.
*
* @param message The error message.
*/
public FindException(String message) {
super("Bruh... " + message + "\nPlease follow the format:\nfind {KEYWORD}");
}
}
17 changes: 8 additions & 9 deletions src/main/java/homie/Homie.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package homie;

import javax.imageio.IIOException;
import java.io.IOException;
import java.util.Scanner;

/**
* A chatbot programme named Homie that helps you keep track
* A chatbot program named Homie that helps you keep track
* of to-do tasks, deadlines and events. Date and time can be specified for deadlines and events.
* Other functions include adding tasks, finding tasks, marking or un-marking tasks as done,
* deleting tasks and listing tasks.
Expand All @@ -16,7 +14,7 @@ public class Homie {
private Ui ui;

/**
* Constructor for Homie class
* Constructor for Homie class. Initialise storage and task list to be used later.
*/
public Homie() {
this.ui = new Ui();
Expand All @@ -26,19 +24,20 @@ public Homie() {
System.out.println(e.getMessage());
}
this.tasks = new TaskList(storage.loadTasksFromFile());
ui.showLoadingError();
}

/**
* Returns a String response based on user input to the GUI.
*/
public String getResponse(String input) throws HomieException {
public String getResponse(String input) {
Parser parser = new Parser(this.tasks, this.ui, this.storage);
try {
String outputResponse = parser.parse(input);
return outputResponse;
} catch (HomieException | TodoException e) {
return parser.parse(input);
} catch (HomieException | TodoException | EventException | DeadlineException | UnmarkException | MarkException
| DeleteException | FindException e) {
return e.getMessage();
} catch (Exception ex) {
return "Invalid Command!!";
}
}
}
5 changes: 3 additions & 2 deletions src/main/java/homie/HomieException.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package homie;

/**
* Homie Exception class
* Homie Exception class. Handles all exceptions related to Homie class.
* Thrown when invalid commands are given by user.
*/
public class HomieException extends Exception {
public HomieException(String message) {
super(message);
super("Bruh... Invalid command!\nPlease try again.");
}
}
2 changes: 1 addition & 1 deletion src/main/java/homie/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.application.Application;

/**
* A launcher class to workaround classpath issues.
* A launcher class to workaround classpath issues. Entrypoint for Homie.
*/
public class Launcher {
public static void main(String[] args) {
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/homie/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package homie;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

/**
* Controller for MainWindow. Provides the layout for the other controls.
*/
Expand All @@ -17,13 +17,11 @@ public class MainWindow extends AnchorPane {
private VBox dialogContainer;
@FXML
private TextField userInput;
@FXML
private Button sendButton;

private Homie homie;

private Image userImage = new Image(this.getClass().getResourceAsStream("/images/gojo.png"));
private Image homieImage = new Image(this.getClass().getResourceAsStream("/images/homie.png"));
private final Image userImage = new Image(this.getClass().getResourceAsStream("/images/user.png"));
private final Image homieImage = new Image(this.getClass().getResourceAsStream("/images/homie.png"));

/**
* Initializes the chatbot GUI and also instantly shows a welcome message.
Expand All @@ -32,9 +30,8 @@ public class MainWindow extends AnchorPane {
public void initialize() {
scrollPane.vvalueProperty().bind(dialogContainer.heightProperty());
Ui ui = new Ui();
String welcomeMessage = ui.showWelcomeMessage();
String welcomeMessage = ui.getWelcomeMessage();
dialogContainer.getChildren().add(DialogBox.getHomieDialog(welcomeMessage, homieImage));

}

public void setHomie(Homie h) {
Expand All @@ -46,7 +43,7 @@ public void setHomie(Homie h) {
* the dialog container. Clears the user input after processing.
*/
@FXML
private void handleUserInput() throws HomieException {
private void handleUserInput() {
String input = userInput.getText();
String response = homie.getResponse(input);
dialogContainer.getChildren().addAll(
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/homie/MarkException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package homie;

/**
* Mark exception class. Handles all exceptions related to mark command.
* Thrown when no index is given as a parameter, or index out of range.
*/
public class MarkException extends Exception {
/**
* Constructor for MarkException class.
*
* @param message The error message.
*/
public MarkException(String message) {
super("Bruh... " + message + "\nPlease follow the format:\nmark {INDEX}");
}
}
Loading

0 comments on commit 453ee95

Please sign in to comment.