From d6ecfe233a635c836508a321b8ae9038d6e834c9 Mon Sep 17 00:00:00 2001 From: limgl1998 Date: Tue, 15 Sep 2020 21:17:31 +0800 Subject: [PATCH] Fixed some naming issues --- src/main/java/duke/Command/Message.java | 2 +- src/main/java/duke/FileIO/FileIO.java | 25 ++++++++++++++----------- src/main/java/duke/Tasks/Deadline.java | 4 +--- src/main/java/duke/Tasks/Event.java | 5 +---- src/main/java/duke/Tasks/Task.java | 2 +- src/main/java/duke/Tasks/TaskList.java | 14 +++++++------- src/main/java/duke/Tasks/ToDo.java | 2 -- text-ui-test/data/data.txt | 4 ++++ 8 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 text-ui-test/data/data.txt diff --git a/src/main/java/duke/Command/Message.java b/src/main/java/duke/Command/Message.java index 6f3096fa75..a0555dc9de 100644 --- a/src/main/java/duke/Command/Message.java +++ b/src/main/java/duke/Command/Message.java @@ -52,7 +52,7 @@ public static void printInvalidTaskNumber(int numberOfTasks) { System.out.println(" \u2639 OOPS!!! Please input a task number between 1 and " + numberOfTasks + "."); } - public static void printEmptyTasklist() { + public static void printEmptyTaskList() { System.out.println(" \u2639 OOPS!!! List is empty"); } diff --git a/src/main/java/duke/FileIO/FileIO.java b/src/main/java/duke/FileIO/FileIO.java index e0df83edd4..799a953512 100644 --- a/src/main/java/duke/FileIO/FileIO.java +++ b/src/main/java/duke/FileIO/FileIO.java @@ -12,8 +12,11 @@ import java.util.Scanner; public class FileIO { + + public static final int INDEX_OF_TASK_TYPE = 1; + public static void readFromFile() { - if (!doesFileExist()) { + if (doesFileNotExist()) { return; } File data = new File("data/data.txt"); @@ -27,7 +30,7 @@ public static void readFromFile() { } } - private static boolean doesFileExist() { + private static boolean doesFileNotExist() { File folder = new File("data"); if (!folder.exists()) { System.out.println("\u2639 OOPS!!! Folder does not exist. Creating a folder named \"data\" in the same directory..."); @@ -36,7 +39,7 @@ private static boolean doesFileExist() { System.out.println("Folder is created successfully."); } else { System.out.println("Please create a folder named \"data\" in the same directory manually."); - return false; + return true; } } File data = new File("data/data.txt"); @@ -50,14 +53,14 @@ private static boolean doesFileExist() { System.out.println("Please create a text file named \"data\" in the \"data\" folder manually."); } } catch (IOException e) { - return false; + return true; } } - return true; + return false; } public static void writeToFile(TaskList taskList) { - if (!doesFileExist()) { + if (doesFileNotExist()) { return; } File data = new File("data/data.txt"); @@ -65,7 +68,7 @@ public static void writeToFile(TaskList taskList) { FileWriter fw = new FileWriter(data.getAbsolutePath()); ArrayList list = taskList.getList(); for (int i = 0; i < taskList.getNumberOfTasks(); i++) { - String input = handleStatusAndDescription(list, i); + String input = formatListDataIntoStorageForm(list, i); fw.write(input + "\n"); } fw.close(); @@ -74,18 +77,18 @@ public static void writeToFile(TaskList taskList) { } } - private static String handleStatusAndDescription(ArrayList list, int index) { + private static String formatListDataIntoStorageForm(ArrayList list, int index) { String output; String input = list.get(index).getStatusAndDescription(); - switch (input.strip().toCharArray()[1]) { + switch (input.strip().toCharArray()[INDEX_OF_TASK_TYPE]) { case ('T'): output = "todo " + list.get(index).getDescription(); break; case ('D'): - output = "deadline " + list.get(index).getDescription() + "/by " + list.get(index).getAdditionalInfomation(); + output = "deadline " + list.get(index).getDescription() + "/by " + list.get(index).getAdditionalInformation(); break; case ('E'): - output = "event " + list.get(index).getDescription() + "/at " + list.get(index).getAdditionalInfomation(); + output = "event " + list.get(index).getDescription() + "/at " + list.get(index).getAdditionalInformation(); break; default: return null; diff --git a/src/main/java/duke/Tasks/Deadline.java b/src/main/java/duke/Tasks/Deadline.java index 369164470b..dee88f28ea 100644 --- a/src/main/java/duke/Tasks/Deadline.java +++ b/src/main/java/duke/Tasks/Deadline.java @@ -1,7 +1,5 @@ package duke.Tasks; -import duke.Tasks.Task; - public class Deadline extends Task { protected String by; @@ -16,7 +14,7 @@ public String getStatusAndDescription() { } @Override - public String getAdditionalInfomation() { + public String getAdditionalInformation() { return by; } } diff --git a/src/main/java/duke/Tasks/Event.java b/src/main/java/duke/Tasks/Event.java index 3e1f4cccde..978380f79b 100644 --- a/src/main/java/duke/Tasks/Event.java +++ b/src/main/java/duke/Tasks/Event.java @@ -1,7 +1,5 @@ package duke.Tasks; -import duke.Tasks.Task; - public class Event extends Task { protected String at; @@ -19,8 +17,7 @@ public String getStatusAndDescription() { return "[E]" + super.getStatusAndDescription() + "(at: " + at + ")"; } - @Override - public String getAdditionalInfomation() { + public String getAdditionalInformation() { return at; } } diff --git a/src/main/java/duke/Tasks/Task.java b/src/main/java/duke/Tasks/Task.java index c29db9dc83..6446e05159 100644 --- a/src/main/java/duke/Tasks/Task.java +++ b/src/main/java/duke/Tasks/Task.java @@ -29,7 +29,7 @@ public String getStatusAndDescription() { return getStatusIcon() + description; } - public String getAdditionalInfomation() { + public String getAdditionalInformation() { return null; } } diff --git a/src/main/java/duke/Tasks/TaskList.java b/src/main/java/duke/Tasks/TaskList.java index 5986c9dd11..b980395ec5 100644 --- a/src/main/java/duke/Tasks/TaskList.java +++ b/src/main/java/duke/Tasks/TaskList.java @@ -23,7 +23,7 @@ public int getNumberOfTasks() { public void printTaskList() { if (list.isEmpty()) { - Message.printEmptyTasklist(); + Message.printEmptyTaskList(); return; } System.out.println(" Here are the tasks in your list:"); @@ -62,7 +62,7 @@ public void addTask(String description, boolean printMessage) { list.add(new ToDo(description)); if (printMessage) { Message.printGotIt(); - printStatusDescriptionAndNumberOftasks(); + printStatusDescriptionAndNumberOfTasks(); } } catch (DukeException e) { Message.printEmptyTodoDescription(); @@ -86,7 +86,7 @@ public void addEvent(String description, boolean printMessage) { list.add(new Event(eventInformation[0], eventInformation[1].strip())); if (printMessage) { Message.printGotIt(); - printStatusDescriptionAndNumberOftasks(); + printStatusDescriptionAndNumberOfTasks(); } } @@ -107,12 +107,12 @@ public void addDeadline(String description, boolean printMessage) { list.add(new Deadline(deadlineInformation[0], deadlineInformation[1].strip())); if (printMessage) { Message.printGotIt(); - printStatusDescriptionAndNumberOftasks(); + printStatusDescriptionAndNumberOfTasks(); } } - private void printStatusDescriptionAndNumberOftasks() { - System.out.println(" " + list.get(list.size()-1).getStatusAndDescription()); + private void printStatusDescriptionAndNumberOfTasks() { + System.out.println(" " + list.get(list.size() - 1).getStatusAndDescription()); Message.printNumberOfTasksInList(list.size()); } @@ -143,7 +143,7 @@ public void deleteTask(String command) { private boolean isTaskListEmptyOrIsCommandTypeInvalid(String command) { if (list.isEmpty()) { - Message.printEmptyTasklist(); + Message.printEmptyTaskList(); return true; } else if (command.isEmpty() || !GeneralMethods.isNumeric(command)) { Message.printInvalidTaskNumber(list.size()); diff --git a/src/main/java/duke/Tasks/ToDo.java b/src/main/java/duke/Tasks/ToDo.java index 306804e507..77fc2b35da 100644 --- a/src/main/java/duke/Tasks/ToDo.java +++ b/src/main/java/duke/Tasks/ToDo.java @@ -1,7 +1,5 @@ package duke.Tasks; -import duke.Tasks.Task; - public class ToDo extends Task { public ToDo(String description) { diff --git a/text-ui-test/data/data.txt b/text-ui-test/data/data.txt new file mode 100644 index 0000000000..311d24c6ba --- /dev/null +++ b/text-ui-test/data/data.txt @@ -0,0 +1,4 @@ +todo borrow book +done 1 +event project meeting /at Mon 2-4pm +done 2