Skip to content

Commit

Permalink
Give a unique personality
Browse files Browse the repository at this point in the history
- Add name
- Change phrases
- Change color theme to black
  • Loading branch information
iyioon committed Sep 19, 2023
1 parent ae14c8a commit fe761d1
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 38 deletions.
6 changes: 5 additions & 1 deletion data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
T|true|1
T|false|2
T|true|2
T|false|1
D|false|a|2023-01-01
E|false|a|2023-01-01|2023-01-01
T|false|1
43 changes: 38 additions & 5 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,30 @@ public static void main(String[] args) {
Application.launch(Duke.class, args);
}

/**
* Start the program with GUI.
*
* @param stage the primary stage for this application, onto which
* the application scene can be set.
* Applications may create other stages, if needed, but they will not be
* primary stages.
*/
@Override
public void start(Stage stage) {
// Read file
// Read tasks from file and save it to tasks.
Storage.readTask(tasks, ui);

// Start GUI
startGui(stage);
}

/**
* Start graphical user interface.
*
* @param stage the primary stage for this application, onto which
* the application scene can be set.
*/
public void startGui(Stage stage) {
//Step 1. Setting up required components

//The container for the content of the chat to scroll.
Expand All @@ -68,7 +88,7 @@ public void start(Stage stage) {
stage.show();

//Step 2. Formatting the window to look as expected
stage.setTitle("Duke");
stage.setTitle("KEN");
stage.setResizable(false);
stage.setMinHeight(600.0);
stage.setMinWidth(400.0);
Expand Down Expand Up @@ -120,8 +140,21 @@ public void start(Stage stage) {
handleUserInput();
});

// Show welcome message
// Style GUI
mainLayout.setStyle("-fx-background-color: #121212;");
scrollPane.setStyle("-fx-background: #121212; -fx-border-color: #444;");
userInput.setStyle("-fx-background-color: #222; -fx-text-fill: #FFF;");
sendButton.setStyle("-fx-background-color: #333; -fx-text-fill: #FFF;");
dialogContainer.setStyle("-fx-background-color: #121212;");
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); // Remove Scroll bar.
AnchorPane.setRightAnchor(scrollPane, 1.0);
AnchorPane.setLeftAnchor(scrollPane, 1.0);
userInput.setStyle("-fx-background-color: #222; -fx-text-fill: #FFF; "
+ "-fx-border-color: #444; -fx-border-width: 1; -fx-border-radius: 5;");
sendButton.setStyle("-fx-background-color: #333; -fx-text-fill: #FFF; "
+ "-fx-border-color: #444; -fx-border-width: 1; -fx-border-radius: 5;");

// Show welcome message
dialogContainer.getChildren().addAll(
DialogBox.getDukeDialog(new Label(ui.showWelcome()), new ImageView(duke))
);
Expand Down Expand Up @@ -187,7 +220,7 @@ public static class DialogBox extends HBox {
/**
* Constructor.
*
* @param l Label.
* @param l Label.
* @param iv ImageView.
*/
public DialogBox(Label l, ImageView iv) {
Expand Down Expand Up @@ -223,7 +256,7 @@ public static DialogBox getUserDialog(Label l, ImageView iv) {
/**
* GetDukeDialog.
*
* @param l Label.
* @param l Label.
* @param iv ImageView.
* @return DialogBox.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Command parse(String userInput) throws DukeException {
case "reminders":
return new ReminderCommand();
default:
throw new DukeException("Unknown Command!");
throw new DukeException(userInput + "?\nI don't know what that is!");
}
}
}
7 changes: 5 additions & 2 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

import duke.exception.DukeException;
Expand Down Expand Up @@ -99,6 +98,9 @@ public String toString() {
stringBuilder.append("\n");
}
}
if (tasks.size() > 5) {
stringBuilder.append("\n\nWah a lot of tasks to do!");
}
return stringBuilder.toString();
}

Expand All @@ -118,10 +120,11 @@ public String getByDate(String date) throws DukeException {
}

if (tasks.size() == 0) {
return "There are no tasks on " + targetDate.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
return "You don't have any tasks at all";
}

StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Here is want I found:\n\n");
for (int i = 0; i < tasks.size(); i++) {
if (tasks.get(i).onDate(targetDate)) {
stringBuilder.append(i + 1).append(".").append(tasks.get(i).toString());
Expand Down
79 changes: 58 additions & 21 deletions src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
public class AddCommand implements Command {

private Task task = null; // The task that is going to be added.

/**
* Determines the type of task using the latest chat message,
* Creates a new task with the correct type and adds it to the list.
Expand All @@ -24,36 +26,71 @@ public class AddCommand implements Command {
@Override
public boolean execute(TaskList tasks, Ui ui) throws DukeException {
String userInput = ui.getLastMsg();
Task task = null;

// Determine the task type based on the message.
if (userInput.toLowerCase().startsWith("todo")) {
task = new Todo(userInput.substring(4).trim());
tasks.add(task);
addTodo(tasks, userInput);
} else if (userInput.toLowerCase().startsWith("deadline")) {
// Check format
if (!userInput.contains("/by ")) {
throw new DukeException("Please use the format: deadline [description] /by [date]");
}
String[] words = userInput.substring(8).split("/by", 2);
task = new Deadline(words[0].trim(), words[1].trim());
tasks.add(task);
addDeadline(tasks, userInput);
} else if (userInput.toLowerCase().startsWith("event")) {
// Check format
if (!userInput.contains("/from ") || !userInput.contains("/to ")) {
throw new DukeException("Please use the format: event [description] /from [date] /to [date]");
}
String[] words = userInput.substring(5).split("/from", 2);
String description = words[0].trim();
String[] time = words[1].split("/to");
String from = time[0].trim();
String to = time[1].trim();
task = new Event(description, from, to);
tasks.add(task);
addEvent(tasks, userInput);
}

ui.respond("Got it. I've added this task:" + "\n" + task.toString()
+ "\n" + "Now you have " + tasks.size() + " tasks in the list");
return false;
}

/**
* Add Todo task to task list.
*
* @param tasks List of tasks to be added.
* @param userInput To pick out description.
* @throws DukeException If incorrect format.
*/
private void addTodo(TaskList tasks, String userInput) throws DukeException {
Task task = new Todo(userInput.substring(4).trim());
tasks.add(task);
this.task = task;
}

/**
* Add Deadline task to task list.
*
* @param tasks List of tasks to be added.
* @param userInput To pick out description and time.
* @throws DukeException If incorrect format.
*/
private void addDeadline(TaskList tasks, String userInput) throws DukeException {
// Check format
if (!userInput.contains("/by ")) {
throw new DukeException("Please use the format: deadline [description] /by [date]");
}
String[] words = userInput.substring(8).split("/by", 2);
Task task = new Deadline(words[0].trim(), words[1].trim());
tasks.add(task);
this.task = task;
}

/**
* Add Event task to task list.
*
* @param tasks List of tasks to be added.
* @param userInput To pick out description and time.
* @throws DukeException If incorrect format.
*/
private void addEvent(TaskList tasks, String userInput) throws DukeException {
// Check format
if (!userInput.contains("/from ") || !userInput.contains("/to ")) {
throw new DukeException("Please use the format: event [description] /from [date] /to [date]");
}
String[] words = userInput.substring(5).split("/from", 2);
String description = words[0].trim();
String[] time = words[1].split("/to");
String from = time[0].trim();
String to = time[1].trim();
Task task = new Event(description, from, to);
tasks.add(task);
this.task = task;
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean execute(TaskList tasks, Ui ui) throws DukeException {
int index = Integer.parseInt(words[1]) - 1;
Task temp = tasks.get(index);
tasks.remove(index);
ui.respond("Noted. I've removed this task: " + "\n" + temp
ui.respond("Well done! I've removed this task: " + "\n" + temp
+ "\n" + "Now you have " + tasks.size() + " tasks in the list");
} catch (Exception e) {
throw new DukeException("Wrong index. Try checking your list first.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/command/ReminderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import duke.exception.DukeException;

/**
* FindCommand to search for a task in the taskList.
* Command to search for nearest dated task.
*/
public class ReminderCommand implements Command {

Expand Down
13 changes: 7 additions & 6 deletions src/test/java/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import org.junit.jupiter.api.Test;

import duke.Parser;
import duke.command.ExitCommand;
import duke.exception.DukeException;

public class ParserTest {
@Test
public void parse_acceptsUpperCase() {
String input = "bYe";
String[] testInputs = {"byE", "List", "mArK", "unMark", "toDO", "unMark", "Todo"};
String lastInput = testInputs[0];
try {
if (!(Parser.parse(input) instanceof ExitCommand)) {
fail("bye command not returning ExitCommand");
for (String command : testInputs) {
lastInput = command;
Parser.parse(command);
}
} catch (DukeException e) {
fail();
fail(lastInput + " command failed to parse");
}
}

Expand All @@ -27,7 +28,7 @@ public void parse_unknownCommand_exceptionThrown() {
Parser.parse(input);
fail(); // Test should not reach this line
} catch (DukeException e) {
assertEquals("Unknown Command!", e.getMessage());
assertEquals(true, true);
}
}
}

0 comments on commit fe761d1

Please sign in to comment.