diff --git a/data/duke.txt b/data/duke.txt new file mode 100644 index 0000000000..cde2f8b626 --- /dev/null +++ b/data/duke.txt @@ -0,0 +1 @@ +1. [E][✗] event AS (at: 16) diff --git a/docs/README.md b/docs/README.md index fd44069597..dfc47a5490 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,19 +2,151 @@ ## Features -### Feature 1 -Description of feature. +### 1. Add Todo +Add a todo task to your task list. + +### 2. Add Deadline +Add a deadline to your task list. + +### 3. Add Event +Add an event to your task list. + +### 4. Mark task as Done +Mark a task in your task list as done. + +### 5. List all tasks +List all tasks in your task list. + +### 6. Delete task +Delete a task from your task list. + +### 7. Find task +Find tasks containing a keyword. + +### 8. Save task list +Save your task list to a .txt file. ## Usage -### `Keyword` - Describe action +### `todo ` - Add a Todo task -Describe action and its outcome. +Add a Todo task to your task list. -Example of usage: +Example of usage: -`keyword (optional arguments)` +`todo read book` Expected outcome: -`outcome` +`____________________________________________________________ +Got it. I've added this task: ` +`[T][✗] read book` +`Now you have 1 tasks in the list.` +`____________________________________________________________` + +### `deadline /by ` - Add a Deadline + +Add a Deadline task to your task list. + +Example of usage: + +`deadline return book /by Monday` + +Expected outcome: + +`____________________________________________________________ +Got it. I've added this task: ` +`[D][✗] return book (by: Monday)` +`Now you have 2 tasks in the list.` +`____________________________________________________________` + +### `event /at ` - Add an Event + +Add an Event task to your task list. + +Example of usage: + +`event book fair /at 5pm Tuesday` + +Expected outcome: + +`____________________________________________________________ +Got it. I've added this task: ` +`[E][✘] book fair (at: 5pm Tuesday)` +`Now you have 3 tasks in the list.` +`____________________________________________________________` + +### `done ` - Mark task as done + +Mark a task in your task list as done. + +Example of usage: + +`done 1` + +Expected outcome: + +`____________________________________________________________ +Nice! I've marked this task as done: ` +`[[T][✓] read book` +`____________________________________________________________` + +### `list` - List all tasks + +List all tasks in your task list. + +Example of usage: + +`list` + +Expected outcome: + +`____________________________________________________________ +Here are the tasks in your list: ` +`1. [T][✓] read book` +`2. [D][✘] return book (by: Monday)` +`3. [E][✘] book fair (at: 5pm Tuesday)` +`____________________________________________________________` + +### `delete ` - Delete a task + +Delete a task from your task list. + +Example of usage: + +`delete 1` + +Expected outcome: + +`____________________________________________________________` +`Removed: [T][✓] read book` +`Now you have 2 task(s) in your list` +`____________________________________________________________` + +### `find ` - Find tasks + +Find tasks with matching keyword. + +Example of usage: + +`find book` + +Expected outcome: + + +`Here are the matching tasks in your list: ` +`1. [D][✘] return book (by: Monday)` +`2. [E][✘] book fair (at: 5pm Tuesday)` + +### `save` - Save task list + +Save task list to .txt file. + +Example of usage: + +`save` + +Expected outcome: + + `Successfully saved to file!` + diff --git a/src/main/duke/Duke.java b/src/main/duke/Duke.java new file mode 100644 index 0000000000..a65f4c979d --- /dev/null +++ b/src/main/duke/Duke.java @@ -0,0 +1,115 @@ +package main.duke; +import java.util.Scanner; + + +public class Duke { + public static void main(String[] args) { + //Generates a greeting + greeting(); + request(); + } + + public static void request(){ + Scanner in = new Scanner(System.in); + Task[] list = new Task[100]; + String line; + int i=0,j; + int task_count = 0; + while(true) { + String status ="[✗] "; + line = in.nextLine(); + + if (line.equals("bye")){ + System.out.println("____________________________________________________________\n" + +"Bye. Hope to see you again soon!\n" + +"____________________________________________________________\n"); + break; + }else if(line.equals("list")){ + for(j=0;j list, int i) { + try { + File myObj = new File("..\\..\\..\\..\\ip\\data\\duke.txt"); + if (myObj.createNewFile()) { + System.out.println("File created!"); + } else { + System.out.println("File already exists."); + } + } catch (IOException var7) { + System.out.println("An error occurred."); + var7.printStackTrace(); + } + + try { + FileWriter myWriter = new FileWriter("..\\..\\..\\..\\ip\\data\\duke.txt"); + + for(int j = 0; j < i; ++j) { + String timing = ""; + Object var10000; + String classtype; + if (list.get(j) instanceof Deadline) { + classtype = "[D]"; + var10000 = list.get(j); + timing = "(by: " + ((Deadline)var10000).getBy() + ")"; + } else if (list.get(j) instanceof Todo) { + classtype = "[T]"; + } else if (list.get(j) instanceof Event) { + classtype = "[E]"; + var10000 = list.get(j); + timing = "(at: " + ((Event)var10000).getWhen() + ")"; + } else { + classtype = "task"; + } + + if (((Task)list.get(j)).isDone) { + myWriter.write(j + 1 + ". " + classtype + " [✓] " + ((Task)list.get(j)).description + " " + timing + "\n"); + } else { + myWriter.write(j + 1 + ". " + classtype + " [X] " + ((Task)list.get(j)).description + " " + timing + "\n"); + } + } + + myWriter.close(); + System.out.println("Successfully saved to the file."); + } catch (IOException var8) { + System.out.println("An error occurred."); + var8.printStackTrace(); + } + + } + + public File checkFileExists(String filePath) throws IOException { + File dataFile = new File(filePath); + if (!dataFile.exists()) { + dataFile.createNewFile(); + } + + return dataFile; + } + /** + * generate list from file + * ... + */ + public List readFile() { + ArrayList taskList = new ArrayList(); + + try { + File dataFile = this.checkFileExists("..\\..\\..\\..\\ip\\data\\duke.txt"); + Scanner in = new Scanner(dataFile); + + while(in.hasNext()) { + String line = in.nextLine(); + String[] taskDetails = line.split(" "); + String var6 = taskDetails[1]; + byte var7 = -1; + switch(var6.hashCode()) { + case 89652: + if (var6.equals("[D]")) { + var7 = 1; + } + break; + case 89683: + if (var6.equals("[E]")) { + var7 = 2; + } + break; + case 90148: + if (var6.equals("[T]")) { + var7 = 0; + } + } + + switch(var7) { + case 0: + taskList.add(new Todo(taskDetails[3])); + break; + case 1: + taskList.add(new Deadline(taskDetails[3], taskDetails[4])); + break; + case 2: + taskList.add(new Event(taskDetails[3], taskDetails[4])); + break; + default: + taskList.add(new Task(taskDetails[3])); + } + + if (taskDetails[2].equals("[✓]")) { + int taskIndex = taskList.size() - 1; + ((Task)taskList.get(taskIndex)).markAsDone(); + } + } + } catch (IOException e) { + } + + return taskList; + } +} \ No newline at end of file diff --git a/src/main/java/Task.class b/src/main/java/Task.class new file mode 100644 index 0000000000..f4194190d7 Binary files /dev/null and b/src/main/java/Task.class differ diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..7cbfb4fc1e --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,20 @@ +public class Task { + protected String description; + protected boolean isDone; + protected int listCount; + + + public Task(String description) { + this.description = description; + this.isDone = false; + this.listCount = 0; + } + + public int length() { + return listCount; //return tick or X symbols + } + public void markAsDone(){ + this.isDone = true; + } + +} \ No newline at end of file diff --git a/src/main/java/TaskList.java b/src/main/java/TaskList.java new file mode 100644 index 0000000000..dc9bfe16ad --- /dev/null +++ b/src/main/java/TaskList.java @@ -0,0 +1,184 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +import java.util.*; + +public class TaskList { + public static List list; + public static int task_count; + + //tasks init + public TaskList() { + list = new ArrayList(); + task_count = 0; + } + + public TaskList(List list) { + TaskList.list = list; + task_count = list.size(); + } + + /** + * print list values based on integer i + * ... + */ + public void printList(int i) { + for(int j = 0; j < i; ++j) { + String timing = ""; + String classtype; + if (list.get(j) instanceof Deadline) { + classtype = "[D]"; + timing = "(by: " + ((Deadline)list.get(j)).getBy() + ")"; + } else if (list.get(j) instanceof Todo) { + classtype = "[T]"; + } else if (list.get(j) instanceof Event) { + classtype = "[E]"; + timing = "(at: " + ((Event)list.get(j)).getWhen() + ")"; + } else { + classtype = "[T]"; + } + + if (((Task)list.get(j)).isDone) { + System.out.println(j + 1 + ". " + classtype + "[✓]" + ((Task)list.get(j)).description + timing); + } else { + System.out.println(j + 1 + ". " + classtype + "[✗] " + ((Task)list.get(j)).description + timing); + } + } + + } + + /** + * print list values based on list + * ... + */ + public static void printList(List list) { + for(int j=0;j returnList() { + return list; + } + + /** + * find matching tasks in list + * + */ + public static void Find(String description) { + List returnList = new ArrayList(); + System.out.println(" Here are the matching tasks in your list: "); + + for(int i = 0; i < list.size(); ++i) { + Task task = (Task)list.get(i); + if (task.description.contains(description)) { + returnList.add(i, (Task)list.get(i)); + } + } + + printList(returnList); + } +} \ No newline at end of file diff --git a/src/main/java/Todo.class b/src/main/java/Todo.class new file mode 100644 index 0000000000..bf38274315 Binary files /dev/null and b/src/main/java/Todo.class differ diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 0000000000..30c8f69109 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,16 @@ +public class Todo extends Task { + protected boolean isDone; + + public Todo(String description) { + super(description); + isDone = false; + } + + public boolean isDone(){ + return isDone; + } + + public void setDone(boolean Done){ + this.isDone = Done; + } +} diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 0000000000..ef3a5e033b --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,47 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +public class Ui { + public Ui() { + } + /** + * bye msg + * ... + */ + public void bye() { + System.out.println("____________________________________________________________\nBye. Hope to see you again soon!\n____________________________________________________________\n"); + } + + /** + * error message + * ... + */ + public void oops(String desc) { + System.out.println("____________________________________________________________\n☹ OOPS!!! The description of a " + desc + " cannot be empty."); + System.out.println("____________________________________________________________\n"); + } + + /** + * error message 2 + * ... + */ + public void dunno() { + System.out.println("____________________________________________________________"); + System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-( "); + System.out.println("_____________________________________________________________"); + } + + /** + * greeting message + * + * ... + */ + public static void greeting() { + System.out.println("____________________________________________________________"); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?"); + System.out.println("____________________________________________________________"); + } +}