diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 6d0333966..5a8717634 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,6 +1,5 @@ package duke; - import duke.exception.FolderNotFoundException; import duke.exception.NoKeyException; import duke.parser.Parser; @@ -15,8 +14,7 @@ * to keep track of the different type of tasks in their daily lives */ public class Duke { - - public static void main(String[] args) throws IOException{ + public static void main(String[] args) throws IOException { Storage storage = new Storage("data", "data/Duke.txt"); Ui ui = new Ui(); Ui.sayHi(); @@ -40,7 +38,6 @@ public static void main(String[] args) throws IOException{ Ui.displayErrorIOException(); } } while (!ui.getUserInput().equals("/bye")); - Ui.sayBye(); } } diff --git a/src/main/java/duke/command/Command.java b/src/main/java/duke/command/Command.java index 0ec037f61..cc214d37a 100644 --- a/src/main/java/duke/command/Command.java +++ b/src/main/java/duke/command/Command.java @@ -6,6 +6,5 @@ * execute() */ public abstract class Command { - public abstract void execute(); } diff --git a/src/main/java/duke/command/DeadlineCommand.java b/src/main/java/duke/command/DeadlineCommand.java index 84be3b949..5d1f24d78 100644 --- a/src/main/java/duke/command/DeadlineCommand.java +++ b/src/main/java/duke/command/DeadlineCommand.java @@ -4,15 +4,18 @@ import duke.task.Dateline; import duke.task.TaskList; import duke.task.Tasks; + /** * DeadlineCommand object represents a command that executes * the adding of a new Deadline Task to the TaskList */ -public class DeadlineCommand extends Command{ +public class DeadlineCommand extends Command { String item; + public DeadlineCommand(String item) { this.item = item; } + public void execute() { String[] taskDate = item.split(" /by ", 2); Tasks newDeadline = new Dateline(taskDate[0], false, taskDate[1]); diff --git a/src/main/java/duke/command/DeleteCommand.java b/src/main/java/duke/command/DeleteCommand.java index abf3b6c61..e0d827842 100644 --- a/src/main/java/duke/command/DeleteCommand.java +++ b/src/main/java/duke/command/DeleteCommand.java @@ -3,15 +3,18 @@ import duke.ui.Ui; import duke.task.TaskList; import duke.task.Tasks; + /** * DeleteCommand object represents a command that executes * the deletion of a Task object from the TaskList based on its index */ -public class DeleteCommand extends Command{ +public class DeleteCommand extends Command { protected String item; - public DeleteCommand(String item){ + + public DeleteCommand(String item) { this.item = item; } + public void execute() { Tasks toDelete = TaskList.getTaskList().get(Integer.parseInt(item) - 1); Ui.displayDelete(toDelete); diff --git a/src/main/java/duke/command/EventCommand.java b/src/main/java/duke/command/EventCommand.java index 5eecb6941..7d8427e01 100644 --- a/src/main/java/duke/command/EventCommand.java +++ b/src/main/java/duke/command/EventCommand.java @@ -4,15 +4,18 @@ import duke.task.Event; import duke.task.TaskList; import duke.task.Tasks; + /** * EventCommand object represents a command that executes * the adding of a new Event Task to the TaskList */ -public class EventCommand extends Command{ +public class EventCommand extends Command { String item; + public EventCommand(String item) { this.item = item; } + public void execute() { String[] eventSlashDate = item.split(" /from | /to ", 3); Tasks newEvent = new Event(eventSlashDate[0], false, eventSlashDate[1], eventSlashDate[2]); diff --git a/src/main/java/duke/command/FindCommand.java b/src/main/java/duke/command/FindCommand.java index 319605aab..8fc047c08 100644 --- a/src/main/java/duke/command/FindCommand.java +++ b/src/main/java/duke/command/FindCommand.java @@ -1,5 +1,4 @@ package duke.command; - import duke.ui.Ui; /** * FindCommand object represents a command that executes diff --git a/src/main/java/duke/command/HelpCommand.java b/src/main/java/duke/command/HelpCommand.java index 5f30d35b3..8973c9c9a 100644 --- a/src/main/java/duke/command/HelpCommand.java +++ b/src/main/java/duke/command/HelpCommand.java @@ -1,14 +1,15 @@ package duke.command; import duke.ui.Ui; + /** * HelpCommand object represents a command that executes * and display Help commands */ -public class HelpCommand extends Command{ - +public class HelpCommand extends Command { public HelpCommand() { } + public void execute() { Ui.displayHelp(); } diff --git a/src/main/java/duke/command/ListCommand.java b/src/main/java/duke/command/ListCommand.java index 960b6ca6e..d006e0053 100644 --- a/src/main/java/duke/command/ListCommand.java +++ b/src/main/java/duke/command/ListCommand.java @@ -9,6 +9,7 @@ public class ListCommand extends Command { public ListCommand() { } + public void execute() { Ui.displayList(); } diff --git a/src/main/java/duke/command/MarkCommand.java b/src/main/java/duke/command/MarkCommand.java index 2f74be5e3..5dc535f3d 100644 --- a/src/main/java/duke/command/MarkCommand.java +++ b/src/main/java/duke/command/MarkCommand.java @@ -3,6 +3,7 @@ import duke.ui.Ui; import duke.task.TaskList; import duke.task.Tasks; + /** * MarkCommand object represents a command that executes * the marking of tasks in the TaskList diff --git a/src/main/java/duke/command/ToDoCommand.java b/src/main/java/duke/command/ToDoCommand.java index c61bd7a53..0cd367084 100644 --- a/src/main/java/duke/command/ToDoCommand.java +++ b/src/main/java/duke/command/ToDoCommand.java @@ -3,15 +3,18 @@ import duke.ui.Ui; import duke.task.TaskList; import duke.task.Todo; + /** * ToDoCommand object represents a command that executes * the adding of a to-do task in the TaskList */ -public class ToDoCommand extends Command{ +public class ToDoCommand extends Command { String item; + public ToDoCommand(String item) { this.item = item; } + @Override public void execute() { Todo newToDo = new Todo(item, false); diff --git a/src/main/java/duke/command/UnmarkCommand.java b/src/main/java/duke/command/UnmarkCommand.java index b8f210914..686e47532 100644 --- a/src/main/java/duke/command/UnmarkCommand.java +++ b/src/main/java/duke/command/UnmarkCommand.java @@ -3,16 +3,18 @@ import duke.ui.Ui; import duke.task.TaskList; import duke.task.Tasks; + /** * UnmarkCommand object represents a command that executes * the un-marking of tasks in the TaskList */ -public class UnmarkCommand extends Command{ - +public class UnmarkCommand extends Command { String item; - public UnmarkCommand(String item){ + + public UnmarkCommand(String item) { this.item = item; } + @Override public void execute() { Tasks markTask = TaskList.getTaskList().get(Integer.parseInt(item) - 1); diff --git a/src/main/java/duke/exception/FolderNotFoundException.java b/src/main/java/duke/exception/FolderNotFoundException.java index cf88412b6..99edbc7b2 100644 --- a/src/main/java/duke/exception/FolderNotFoundException.java +++ b/src/main/java/duke/exception/FolderNotFoundException.java @@ -1,5 +1,4 @@ package duke.exception; -public class FolderNotFoundException extends Exception{ - +public class FolderNotFoundException extends Exception { } diff --git a/src/main/java/duke/exception/NoKeyException.java b/src/main/java/duke/exception/NoKeyException.java index cdd5f946f..dfc0a1492 100644 --- a/src/main/java/duke/exception/NoKeyException.java +++ b/src/main/java/duke/exception/NoKeyException.java @@ -1,4 +1,4 @@ package duke.exception; -public class NoKeyException extends Exception{ +public class NoKeyException extends Exception { } diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java index 68e8f6c8d..63c061167 100644 --- a/src/main/java/duke/parser/Parser.java +++ b/src/main/java/duke/parser/Parser.java @@ -6,6 +6,7 @@ public class Parser { /** * Parses the input from user + * * @param userInput Description of task entered by user * @throws NoKeyException If keywords are missing from user input */ @@ -62,7 +63,7 @@ public static void parseCommand(String userInput) throws NoKeyException { command.execute(); break; case "/find": - command= new FindCommand(item); + command = new FindCommand(item); command.execute(); case "/bye": break; diff --git a/src/main/java/duke/storage/Storage.java b/src/main/java/duke/storage/Storage.java index 3c6a47bd0..7c58b2b5e 100644 --- a/src/main/java/duke/storage/Storage.java +++ b/src/main/java/duke/storage/Storage.java @@ -15,6 +15,7 @@ public class Storage { private final String filePath; private final String folderName; + public Storage(String folderName, String filePath) { this.filePath = filePath; this.folderName = folderName; @@ -22,8 +23,9 @@ public Storage(String folderName, String filePath) { /** * Loads user data + * * @throws FolderNotFoundException if folder is not found - * @throws FileNotFoundException if file is not found + * @throws FileNotFoundException if file is not found */ public void load() throws FolderNotFoundException, FileNotFoundException { File folder = new File(folderName); @@ -75,6 +77,7 @@ public void load() throws FolderNotFoundException, FileNotFoundException { /** * Saves user data + * * @throws IOException if trouble accessing files */ public void save() throws IOException { @@ -86,20 +89,20 @@ public void save() throws IOException { } fw.close(); } + public void createNewFile() throws IOException { File f = new File(filePath); if (f.createNewFile()) { System.out.println("File created"); - } - else + } else System.out.println("File already exists"); } + public void createNewFolder() { File folder = new File(folderName); - if(folder.mkdir()) { + if (folder.mkdir()) { System.out.println("Folder created"); - } - else { + } else { System.out.println("Folder already exists"); } } diff --git a/src/main/java/duke/task/Dateline.java b/src/main/java/duke/task/Dateline.java index 1af8a8135..de31a944e 100644 --- a/src/main/java/duke/task/Dateline.java +++ b/src/main/java/duke/task/Dateline.java @@ -1,5 +1,4 @@ package duke.task; - public class Dateline extends Tasks { String dueDate; public Dateline(String item, boolean isMarked, String dueDate) { diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 593086dad..752ca46e9 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -1,5 +1,4 @@ package duke.task; - public class Event extends Tasks { String startDate; String endDate; diff --git a/src/main/java/duke/task/TaskList.java b/src/main/java/duke/task/TaskList.java index 2619b7328..73758123c 100644 --- a/src/main/java/duke/task/TaskList.java +++ b/src/main/java/duke/task/TaskList.java @@ -1,8 +1,11 @@ package duke.task; + import java.util.ArrayList; + public class TaskList { private static int numberOfTasks = 0; private static final ArrayList taskList = new ArrayList<>(); + public static ArrayList getTaskList() { return taskList; } @@ -10,10 +13,12 @@ public static ArrayList getTaskList() { public static int getNumberOfTasks() { return numberOfTasks; } + public static void addToList(Tasks task) { taskList.add(task); numberOfTasks++; } + public static void deleteFromList(int pos) { taskList.remove(pos); numberOfTasks--; diff --git a/src/main/java/duke/task/Tasks.java b/src/main/java/duke/task/Tasks.java index bbddad819..49547a319 100644 --- a/src/main/java/duke/task/Tasks.java +++ b/src/main/java/duke/task/Tasks.java @@ -1,7 +1,4 @@ package duke.task; - -import java.util.ArrayList; - public abstract class Tasks { private String item; private boolean isMarked; diff --git a/src/main/java/duke/task/Todo.java b/src/main/java/duke/task/Todo.java index bf3617486..989cabf9f 100644 --- a/src/main/java/duke/task/Todo.java +++ b/src/main/java/duke/task/Todo.java @@ -1,15 +1,12 @@ package duke.task; public class Todo extends Tasks { - - - public Todo(String item, boolean isMarked) { super(item, isMarked); } + @Override public String toString() { - return "[T]" + super.toString(); } } diff --git a/src/main/java/duke/ui/Ui.java b/src/main/java/duke/ui/Ui.java index fe748a47a..4b20433de 100644 --- a/src/main/java/duke/ui/Ui.java +++ b/src/main/java/duke/ui/Ui.java @@ -13,9 +13,11 @@ public class Ui { public Ui() { userInput = null; } + public String getUserInput() { return userInput; } + public static void sayHi() { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -55,7 +57,7 @@ public static void displayList() { Tasks thisTask = TaskList.getTaskList().get(num - 1); System.out.println("\t " + num + ". " + thisTask); } - System.out.println(DIVIDER +'\n'); + System.out.println(DIVIDER + '\n'); } @@ -79,6 +81,7 @@ public static void displayDelete(Tasks task) { System.out.println("\t Now you have " + (TaskList.getNumberOfTasks() - 1) + " item(s) in your list.\n" + DIVIDER + '\n'); } + public static void displayHelp() { System.out.println(DIVIDER + "\n\t Please read the User Guide in docs/README.md for more help.\n" + DIVIDER + '\n');