Skip to content

Commit

Permalink
Fixed some naming issues
Browse files Browse the repository at this point in the history
  • Loading branch information
limgl1998 committed Sep 15, 2020
1 parent 6e54ad7 commit d6ecfe2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/main/java/duke/Command/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
25 changes: 14 additions & 11 deletions src/main/java/duke/FileIO/FileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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...");
Expand All @@ -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");
Expand All @@ -50,22 +53,22 @@ 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");
try {
FileWriter fw = new FileWriter(data.getAbsolutePath());
ArrayList<Task> 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();
Expand All @@ -74,18 +77,18 @@ public static void writeToFile(TaskList taskList) {
}
}

private static String handleStatusAndDescription(ArrayList<Task> list, int index) {
private static String formatListDataIntoStorageForm(ArrayList<Task> 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;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/duke/Tasks/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke.Tasks;

import duke.Tasks.Task;

public class Deadline extends Task {
protected String by;

Expand All @@ -16,7 +14,7 @@ public String getStatusAndDescription() {
}

@Override
public String getAdditionalInfomation() {
public String getAdditionalInformation() {
return by;
}
}
5 changes: 1 addition & 4 deletions src/main/java/duke/Tasks/Event.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke.Tasks;

import duke.Tasks.Task;

public class Event extends Task {
protected String at;

Expand All @@ -19,8 +17,7 @@ public String getStatusAndDescription() {
return "[E]" + super.getStatusAndDescription() + "(at: " + at + ")";
}

@Override
public String getAdditionalInfomation() {
public String getAdditionalInformation() {
return at;
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/Tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getStatusAndDescription() {
return getStatusIcon() + description;
}

public String getAdditionalInfomation() {
public String getAdditionalInformation() {
return null;
}
}
14 changes: 7 additions & 7 deletions src/main/java/duke/Tasks/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -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());
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/Tasks/ToDo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package duke.Tasks;

import duke.Tasks.Task;

public class ToDo extends Task {

public ToDo(String description) {
Expand Down
4 changes: 4 additions & 0 deletions text-ui-test/data/data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
todo borrow book
done 1
event project meeting /at Mon 2-4pm
done 2

0 comments on commit d6ecfe2

Please sign in to comment.