diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java index 2e71cf1a84..7e34fea891 100644 --- a/src/main/java/Deadline.java +++ b/src/main/java/Deadline.java @@ -1,7 +1,9 @@ +import java.util.Date; + public class Deadline extends Task { - protected String by; + protected Date by; - public Deadline(String description, String by) { + public Deadline(String description, Date by) { super(description); this.by = by; } diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 97244320e4..25c20c3355 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,6 @@ +import java.io.FileNotFoundException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Scanner; @@ -6,14 +9,14 @@ public class Duke { protected static ArrayList taskList = new ArrayList<>(); public static void main(String[] args) throws DukeException, FileNotFoundException { - taskList = FileSaver.loadTask(); + taskList = Storage.load(); Scanner sc = new Scanner(System.in); - ArrayList commandList = new ArrayList<>(); String line = " ____________________________________________________________\n"; - System.out.println(line + - " Hello! I'm Duke\n" + //duke greeting - " What can I do for you?\n" + line); + Ui ui = new Ui(); + Parser parser = new Parser(); + ui.greet(); + int x = 1; //switch do { //to recycle the try catch block try { @@ -21,7 +24,7 @@ public static void main(String[] args) throws DukeException, FileNotFoundExcepti String command = sc.next(); if (command.equals("bye")) { - System.out.println(line + " Bye. Hope to see you again soon!\n" + line); + ui.farewell(); x = 2; //break the do while loop break; } else if (command.equals("list")) { @@ -39,7 +42,7 @@ public static void main(String[] args) throws DukeException, FileNotFoundExcepti System.out.println(line + " Nice! I've marked this task as done:\n" + " [" + taskList.get(taskNum - 1).getStatusIcon() + "]" + taskList.get(taskNum - 1).toString() + "\n" + line); - FileSaver.saveTaskList(taskList); //save file + Storage.saveTaskList(taskList); //save file } else if (command.equals("todo")) { String wordsAfter = sc.nextLine(); @@ -51,7 +54,7 @@ public static void main(String[] args) throws DukeException, FileNotFoundExcepti System.out.print(line + " Got it. I've added this task: " + "\n " + todoTask.toString() + "\n"); System.out.print(" Now you have " + taskList.size() + " tasks in the list." + "\n" + line); - FileSaver.saveTaskList(taskList); //save file + Storage.saveTaskList(taskList); //save file } else if (command.equals("deadline")) { String wordsAfter = sc.nextLine(); @@ -62,17 +65,18 @@ public static void main(String[] args) throws DukeException, FileNotFoundExcepti System.out.print(line + " Got it. I've added this task: " + "\n " + dlTask.toString() + "\n"); System.out.print(" Now you have " + taskList.size() + " tasks in the list." + "\n" + line); - FileSaver.saveTaskList(taskList); //save file + Storage.saveTaskList(taskList); //save file } else if (command.equals("event")) { String wordsAfter = sc.nextLine(); int pos = wordsAfter.indexOf("/"); - Task eTask = new Event(wordsAfter.substring(0, pos), wordsAfter.substring(pos + 3)); - commandList.add(eTask); + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm"); + Task eTask = new Event(wordsAfter.substring(0, pos), sdf.parse(wordsAfter.substring(pos + 3))); + taskList.add(eTask); System.out.print(line + " Got it. I've added this task: " + "\n " + eTask.toString() + "\n" + " Now you have " + taskList.size() + " tasks in the list." + "\n" + line); - FileSaver.saveTaskList(taskList); //save file + Storage.saveTaskList(taskList); //save file } else if (command.equals("delete")) { int taskNum = sc.nextInt(); @@ -80,7 +84,7 @@ public static void main(String[] args) throws DukeException, FileNotFoundExcepti System.out.println(" " + taskList.get(taskNum - 1). toString()); taskList.remove(taskNum - 1); System.out.print(" Now you have " + taskList.size() + "tasks in the list.\n" + line); - FileSaver.saveTaskList(taskList); //save file + Storage.saveTaskList(taskList); //save file } else { throw new DukeException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 0000000000..f7380dd36d --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,9 @@ +import java.text.ParseException; +import java.text.SimpleDateFormat; + +class Parser { + public void formatTime(String time) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm"); + sdf.parse(time); + } +} \ No newline at end of file diff --git a/src/main/java/FileSaver.java b/src/main/java/Storage.java similarity index 94% rename from src/main/java/FileSaver.java rename to src/main/java/Storage.java index 1fc7502949..8e78fbd95d 100644 --- a/src/main/java/FileSaver.java +++ b/src/main/java/Storage.java @@ -8,10 +8,10 @@ import java.util.List; import java.util.Scanner; -public class FileSaver { +public class Storage { private static File file = new File("../duke.txt"); - public static ArrayList loadTask() throws FileNotFoundException { + public static ArrayList load() throws FileNotFoundException { ArrayList taskList = new ArrayList<>(); try { @@ -20,7 +20,7 @@ public static ArrayList loadTask() throws FileNotFoundException { String[] task = sc.nextLine().split("\\|"); String taskType = task[0].trim(); - boolean isTaskDone = task[2].trim().equals("1") ? true : false; + boolean isTaskDone = task[2].trim().equals("1"); switch(taskType) { case "T": diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 0000000000..999f1484cf --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,22 @@ +import java.util.ArrayList; + +public class TaskList { + + private ArrayList taskList = new ArrayList<>(); + + public TaskList(ArrayList taskList) { + this.taskList = taskList; + } + + public void addTask(Task task) { + taskList.add(task); + } + + public void deleteTask(int taskNum) { + this.taskList.remove(taskNum); + } + + public ArrayList getTaskList() { + return taskList; + } +} \ No newline at end of file diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 0000000000..db5a7fb066 --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,21 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class Ui { + + private Scanner sc = new Scanner(System.in); + protected static ArrayList taskList = new ArrayList<>(); + + String line = " ____________________________________________________________\n"; + + public void greet() { //duke greet + System.out.println(line + + " Hello! I'm Duke\n" + + " What can I do for you?\n" + line); + } + + public void farewell() { + System.out.println(line + " Bye. Hope to see you again soon!\n" + line); + } + +}