diff --git a/README.md b/README.md index 8715d4d91..678e0d108 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,30 @@ Prerequisites: JDK 11, update Intellij to the most recent version. | |_| | |_| | < __/ |____/ \__,_|_|\_\___| ``` + +## How to use + +The commands this program uses are; `todo`, `deadline`, `event`, `list`, `mark`, `find`, `delete` and `bye`** +`todo`, `deadline` and `event` are the different types of tasks you can add into your list to keep track of. + +1. `todo`s are the simplest task to add as they do not require you to add in a start/end time, only a description of the task +e.g. `todo lunch` + +2. `deadline`s, as the name suggests, are tasks which have a deadline. The due date or time is indicated after a `/` +e.g. `lunch/12pm` + +3. `event`s are tasks which have a duration, from a start time to an end time +e.g. `lunch/12pm/1pm + +4. `list` shows you the tasks which you have added. You can view them by simply typing `list` + +5. `mark` checks off the task which you have completed. +e.g. `mark 3` + +6. `find` searches your list of tasks to find those which have a certain ketword present. +e.g. `find lunch` + +7. `delete` removes one of the tasks in your list +e.g. `delete 2` + +Finally, `bye` allows you the exit program diff --git a/src/main/java/AddTask.java b/src/main/java/AddTask.java new file mode 100644 index 000000000..1285c7ad7 --- /dev/null +++ b/src/main/java/AddTask.java @@ -0,0 +1,2 @@ +public class AddTask { +} diff --git a/src/main/java/ByeCommand.java b/src/main/java/ByeCommand.java new file mode 100644 index 000000000..d5dc5f1af --- /dev/null +++ b/src/main/java/ByeCommand.java @@ -0,0 +1,2 @@ +public class ByeCommand { +} diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..5ac06844b --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task{ + protected String dueDate; + + public Deadline(String description, String dueBy) { + super(description); + this.dueDate = dueBy; + } + + @Override + public String toString() { + return "[D]" + super.toString() + " (due by: " + dueDate + ")"; + } +} diff --git a/src/main/java/DeleteCommand.java b/src/main/java/DeleteCommand.java new file mode 100644 index 000000000..1ba316b3f --- /dev/null +++ b/src/main/java/DeleteCommand.java @@ -0,0 +1,2 @@ +public class DeleteCommand { +} diff --git a/src/main/java/DisplayMessages.java b/src/main/java/DisplayMessages.java new file mode 100644 index 000000000..0aa0c0b92 --- /dev/null +++ b/src/main/java/DisplayMessages.java @@ -0,0 +1,2 @@ +public class DisplayMessages { +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..afcc3530b 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,180 @@ +import java.util.Scanner; +import java.util.Arrays; public class Duke { + + private static Scanner in = new Scanner(System.in); + private static final Task[] tasks = new Task[100]; + private static final Task[] foundTasks = new Task[100]; + + public static void whatToDo(String line) { + try { + command(line); + } + catch (InvalidCommandException error) { + System.out.println("Try using one of following commands: todo, deadline, event."); + line = in.nextLine(); + whatToDo(line); + } + catch (IndexOutOfBoundsException error) { + System.out.println("Oops! You need to provide a description/time for your task"); + line = in.nextLine(); + whatToDo(line); + } + } + + public static boolean isWordPresent(Task task, String keyword) { + String[] words = (task.description).split(" "); + + for (String temp : words) { + if (temp.compareToIgnoreCase(keyword) == 0) { + return true; + } + } + return false; + } + + public static void command(String line) throws InvalidCommandException { + String exitCommand = "bye"; + String taskList = "list"; + String checkAsDone = "mark"; + String del = "delete"; + String search = "find"; + int numberOfTasks = 0; + + String[] tokens = line.split(" ", 2); + String command = tokens[0]; + + while (!command.equals(exitCommand)) { + if (tokens[0].equals(taskList)) { + System.out.println("Here are your list of tasks to complete!"); + for (int i = 0; i < numberOfTasks; ++i) { + System.out.format("%d. ", (i + 1)); + System.out.println(tasks[i]); + } + line = in.nextLine(); + tokens = line.split(" ", 2); + command = tokens[0]; + } else if (command.equals(checkAsDone)){ + int finishedTask = Integer.parseInt(tokens[1]) - 1; + tasks[finishedTask].markDone(); + System.out.println("Alright! I have marked the task as complete!"); + + for (int i = 0; i < numberOfTasks; ++i) { + System.out.format("%d. ", (i + 1)); + System.out.println(tasks[i]); + } + + line = in.nextLine(); + tokens = line.split(" ", 0); + command = tokens[0]; + } else if (command.equals(del)) { + int taskToDelete = Integer.parseInt(tokens[1]) - 1; + for (int i = taskToDelete; i < (tasks.length - 1); ++i) { + tasks[i] = tasks[i + 1]; + } + --numberOfTasks; + System.out.println("Removed task number " + (taskToDelete + 1) + ". Here are your remaining tasks:"); + for (int i = 0; i < numberOfTasks; ++i) { + System.out.format("%d. ", (i + 1)); + System.out.println(tasks[i]); + } + + line = in.nextLine(); + tokens = line.split(" ", 0); + command = tokens[0]; + } else if (command.equals(search)) { + String itemToFind = tokens[1]; + int searchNumber = 0; + + for (int i = 0; i < numberOfTasks; ++i) { + if (isWordPresent(tasks[i], itemToFind)) { + foundTasks[searchNumber] = tasks[i]; + searchNumber++; + } + } + System.out.println("Tasks matching with " + itemToFind); + for (int i = 0; i < searchNumber; ++i) { + System.out.format("%d. ", (i + 1)); + System.out.println(foundTasks[i]); + } + + line = in.nextLine(); + tokens = line.split(" ", 0); + command = tokens[0]; + } else { + String task = tokens[1]; + switch(command) { + case "todo": + Task t = new ToDo(task); + tasks[numberOfTasks] = t; + tasks[numberOfTasks].isDone = false; + ++numberOfTasks; + break; + case "deadline": + String[] taskDeadline = task.split("/", 2); + String taskDescription = taskDeadline[0]; + String dueBy = taskDeadline[1]; + + Task d = new Deadline(taskDescription, dueBy); + tasks[numberOfTasks] = d; + tasks[numberOfTasks].isDone = false; + ++numberOfTasks; + break; + case "event": + String[] taskEvent = task.split("/", 3); + String eventDescription = taskEvent[0]; + String start = taskEvent[1]; + String end = taskEvent[2]; + + Task e = new Event(eventDescription, start, end); + tasks[numberOfTasks] = e; + tasks[numberOfTasks].isDone = false; + ++numberOfTasks; + break; + default: + System.out.println("Sorry! I couldn't understand your command:( Please try again."); + throw new InvalidCommandException(); + } + System.out.println("added: " + line); + line = in.nextLine(); + tokens = line.split(" ", 0); + command = tokens[0]; + } + } + System.out.println("Bye! Hope to see you again"); + } + public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + String logo = " ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡟⠋⠈⠙⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠤⢤⡀⠀⠀\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠈⢇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠞⠀⠀⢠⡜⣦⠀\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡃⠀⠀⠀⠀⠈⢷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⣠⠀⠀⠀⠀⢻⡘⡇\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠙⢶⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡠⠚⢀⡼⠃⠀⠀⠀⠀⠸⣇⢳\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⠀⣀⠖⠀⠀⠀⠀⠉⠀⠀⠈⠉⠛⠛⡛⢛⠛⢳⡶⠖⠋⠀⢠⡞⠀⠀⠀⠐⠆⠀⠀⣿⢸\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣀⣴⡟⠀⠀⢶⣶⣾⡿⠀⠀⣿⢸\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⡠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣏⠀⠀⠀⣶⣿⣿⡇⠀⠀⢏⡞\n" + + "⠀⠀⠀⠀⠀⠀⢀⡴⠛⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⡾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢦⣤⣾⣿⣿⠋⠀⠀⡀⣾⠁\n" + + "⠀⠀⠀⠀⠀⣠⠟⠁⠀⠀⠀⣀⠀⠀⠀⠀⢀⡟⠈⢀⣤⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⣏⡁⠀⠐⠚⠃⣿⠀\n" + + "⠀⠀⠀⠀⣴⠋⠀⠀⠀⡴⣿⣿⡟⣷⠀⠀⠊⠀⠴⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠀⠀⠀⠀⢹⡆\n" + + "⠀⠀⠀⣴⠃⠀⠀⠀⠀⣇⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⡶⢶⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇\n" + + "⠀⠀⣸⠃⠀⠀⠀⢠⠀⠊⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⢲⣾⣿⡏⣾⣿⣿⣿⣿⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢧\n" + + "⠀⢠⡇⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠈⠛⠿⣽⣿⡿⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜\n" + + "⢀⡿⠀⠀⠀⠀⢀⣤⣶⣟⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇\n" + + "⢸⠇⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇\n" + + "⣼⠀⢀⡀⠀⠀⢷⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡇\n" + + "⡇⠀⠈⠀⠀⠀⣬⠻⣿⣿⣿⡿⠙⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁\n" + + "⢹⡀⠀⠀⠀⠈⣿⣶⣿⣿⣝⡛⢳⠭⠍⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠃⠀\n" + + "⠸⡇⠀⠀⠀⠀⠙⣿⣿⣿⣿⣿⣿⣷⣦⣀⣀⣀⣤⣤⣴⡶⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠇⠀⠀\n" + + "⠀⢿⡄⠀⠀⠀⠀⠀⠙⣇⠉⠉⠙⠛⠻⠟⠛⠛⠉⠙⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠋⠀⠀⠀\n" + + "⠀⠈⢧⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠁⠀⠀⠀⠀\n" + + "⠀⠀⠘⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠞⠁⠀⠀⠀⠀⠀⠀\n" + + "⠀⠀⠀⠀⠱⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀\n" + + "⠀⠀⠀⠀⠀⠀⠛⢦⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⠴⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\n" + + "⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠲⠤⣤⣤⣤⣄⠀⠀⠀⠀⠀⠀⠀⢠⣤⣤⠤⠴⠒⠛⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀"; System.out.println("Hello from\n" + logo); + System.out.println("Hi! My name is Doge. \n Nice to meet you!"); + + String line; + line = in.nextLine(); + whatToDo(line); } } diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..6622efcf7 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task{ + protected String start; + protected String end; + + public Event(String description, String start, String end) { + super(description); + this.start = start; + this.end = end; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + start + " to " + end + ")"; + } +} diff --git a/src/main/java/InvalidCommandException.java b/src/main/java/InvalidCommandException.java new file mode 100644 index 000000000..c6b3a54e2 --- /dev/null +++ b/src/main/java/InvalidCommandException.java @@ -0,0 +1,2 @@ +public class InvalidCommandException extends Exception { +} diff --git a/src/main/java/ListCommand.java b/src/main/java/ListCommand.java new file mode 100644 index 000000000..9f89570cc --- /dev/null +++ b/src/main/java/ListCommand.java @@ -0,0 +1,3 @@ +public class ListCommand { + +} diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..9f37e4e0a --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Duke + diff --git a/src/main/java/MarkCommand.java b/src/main/java/MarkCommand.java new file mode 100644 index 000000000..dc808500b --- /dev/null +++ b/src/main/java/MarkCommand.java @@ -0,0 +1,2 @@ +public class MarkCommand { +} diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..f872d5b13 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,22 @@ + +public class Parser { + + String command; + String taskDescription; + String deadline; + String startDate; + String endDate; + String taskNumber; + boolean shouldQuit = false; + + + public Parser (String userInput) { + String[] tokens = userInput.split(" "); + command = tokens[0]; + + switch(command) { + case "list": + + } + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..dbf3a0fcd --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,25 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatus() { + return (isDone ? "[X]" : "[ ]"); // mark done task with X + } + + public void markDone() { + this.isDone = true; + } + + public void unmarkDone() { + this.isDone = false; + } + + public String toString() { + return getStatus() + " " + description; + } +} diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 000000000..38788ba66 --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,11 @@ +public class ToDo extends Task { + + public ToDo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..99e594237 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,4 @@ +public class Ui { + + +} diff --git a/src/main/java/UnmarkCommand.java b/src/main/java/UnmarkCommand.java new file mode 100644 index 000000000..6d3ac5a36 --- /dev/null +++ b/src/main/java/UnmarkCommand.java @@ -0,0 +1,2 @@ +public class UnmarkCommand { +}