forked from nus-cs2113-AY2324S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nicknamenic/branch-Level-7
Increment to Level 7
- Loading branch information
Showing
10 changed files
with
202 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[E][ ] delimit (from: 2pm to: 4pm) | ||
[D][X] finish cs2113t (by: 2359) | ||
[T][X] help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import exceptions.NocturneException; | ||
import util.Parser; | ||
import util.TaskList; | ||
import util.Ui; | ||
|
||
public class Nocturne { | ||
public static void main(String[] args) throws NocturneException { | ||
public static void main(String[] args) { | ||
TaskList list = new TaskList(); | ||
System.out.println("Good evening. I'm Nocturne."); | ||
System.out.println("What ails you on this fine day?"); | ||
Ui.greetingMessage(); | ||
Parser.getInput(list); | ||
System.out.println("Farewell, and may the fortunes be ever in your favour."); | ||
Ui.farewellMessage(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
package tasks; | ||
|
||
public class Todo extends Task { | ||
public Todo(String description){ | ||
|
||
public Todo(String description) { | ||
super(description); | ||
this.isDone = false; | ||
} | ||
|
||
public Todo(String description, boolean isDone) { | ||
super(description); | ||
isDone = false; | ||
this.isDone = isDone; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + "[" + super.getStatusIcon() + "] " + description; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package util; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.Scanner; | ||
import tasks.Deadline; | ||
import tasks.Event; | ||
import tasks.Task; | ||
import tasks.Todo; | ||
|
||
public class Storage { | ||
private final String PATH = "./data/nocturne.txt"; | ||
private File f; | ||
|
||
public Storage() { | ||
File dir = new File("./data"); | ||
if (!dir.exists()) { | ||
dir.mkdir(); | ||
} | ||
this.f = new File(PATH); | ||
} | ||
|
||
public void saveToFile(TaskList taskList) { | ||
try { | ||
FileWriter fileWriter = new FileWriter(this.f); | ||
fileWriter.write(""); | ||
for (Task task : taskList.tasks) { | ||
fileWriter.append(task.toString()).append("\n"); | ||
} | ||
fileWriter.close(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void readFromFile(TaskList tasks) { | ||
try { | ||
Scanner sc = new Scanner(this.f); | ||
|
||
while(sc.hasNextLine()) { | ||
String data = sc.nextLine(); | ||
String task = data.substring(6); | ||
task = task.replace('(', ' '); | ||
task = task.replace(')', ' '); | ||
boolean isDone = data.charAt(4) == 'X'; | ||
switch (data.charAt(1)) { | ||
case 'D': | ||
String[] deadlineSplit = task.split("by:"); | ||
tasks.addTaskStealth(new Deadline(deadlineSplit[0].trim(), | ||
deadlineSplit[1].trim(), | ||
isDone)); | ||
break; | ||
case 'E': | ||
String[] eventSplit = task.split(":"); | ||
tasks.addTaskStealth(new Event(eventSplit[0].substring(0, | ||
eventSplit[0].length() - 4).trim(), | ||
eventSplit[1].substring(0, eventSplit[1].length() - 2).trim(), | ||
eventSplit[2].trim(), | ||
isDone)); | ||
break; | ||
case 'T': | ||
tasks.addTaskStealth(new Todo(task.trim(), isDone)); | ||
} | ||
} | ||
sc.close(); | ||
} catch (IndexOutOfBoundsException | FileNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,88 @@ | ||
package util; | ||
|
||
import tasks.Task; | ||
|
||
import java.util.ArrayList; | ||
import tasks.Task; | ||
|
||
public class TaskList { | ||
protected ArrayList<Task> tasks = new ArrayList<>(); | ||
protected Storage storage = new Storage(); | ||
|
||
public TaskList() { | ||
this.storage.readFromFile(this); | ||
} | ||
|
||
public void addTask (Task task) { | ||
public void addTask(Task task) { | ||
System.out.println("A task I see. I have added it."); | ||
System.out.println(" " + task); | ||
tasks.add(task); | ||
Ui.printTask(task); | ||
this.tasks.add(task); | ||
this.storage.saveToFile(this); | ||
} | ||
|
||
public void addTaskStealth(Task task) { | ||
this.tasks.add(task); | ||
this.storage.saveToFile(this); | ||
} | ||
|
||
public void deleteTask(int index) { | ||
try { | ||
System.out.println("Should all acquaintance be forgot..." ); | ||
System.out.println(" " + tasks.get(index - 1)); | ||
tasks.remove(index - 1); | ||
System.out.println(tasks.size() + " task(s) remain."); | ||
System.out.println("Should all acquaintance be forgot..."); | ||
Ui.printTask(this.tasks.get(index - 1)); | ||
this.tasks.remove(index - 1); | ||
System.out.println(this.tasks.size() + " task(s) remain."); | ||
} catch (IndexOutOfBoundsException e) { | ||
System.out.println("You are trying to access forbidden territory. Tread carefully."); | ||
Ui.indexOutOfBoundsMessage(); | ||
} | ||
|
||
this.storage.saveToFile(this); | ||
} | ||
|
||
public void listTasks () { | ||
if (tasks.isEmpty()) { | ||
System.out.println("Your list is empty. Try again, when you have become more productive."); | ||
public void listTasks() { | ||
if (this.tasks.isEmpty()) { | ||
Ui.emptyListMessage(); | ||
} | ||
for (int i = 0; i < tasks.size(); i++) { | ||
System.out.print((i + 1) + "."); | ||
System.out.println(tasks.get(i)); | ||
|
||
for(int i = 0; i < this.tasks.size(); ++i) { | ||
System.out.print(i + 1 + "."); | ||
System.out.println(this.tasks.get(i)); | ||
} | ||
|
||
} | ||
|
||
public void markTask (int index) { | ||
public void markTask(int index) { | ||
try { | ||
tasks.get(index - 1).markAsDone(); | ||
(this.tasks.get(index - 1)).markAsDone(); | ||
System.out.println("Congratulations. I have marked this task as finished:"); | ||
System.out.println(" " + tasks.get(index - 1)); | ||
} catch (IndexOutOfBoundsException e) { | ||
System.out.println("You are trying to access forbidden territory. Tread carefully."); | ||
Ui.printTask(this.tasks.get(index - 1)); | ||
} catch (IndexOutOfBoundsException var3) { | ||
Ui.indexOutOfBoundsMessage(); | ||
} | ||
|
||
this.storage.saveToFile(this); | ||
} | ||
|
||
public void unmarkTask (int index) { | ||
public void unmarkTask(int index) { | ||
try { | ||
tasks.get(index - 1).markAsUndone(); | ||
(this.tasks.get(index - 1)).markAsUndone(); | ||
System.out.println("Do not neglect your duties. I have marked this task as unfinished:"); | ||
System.out.println(" " + tasks.get(index - 1)); | ||
Ui.printTask(this.tasks.get(index - 1)); | ||
} catch (IndexOutOfBoundsException e) { | ||
System.out.println("You are trying to access forbidden territory. Tread carefully."); | ||
Ui.indexOutOfBoundsMessage(); | ||
} | ||
|
||
this.storage.saveToFile(this); | ||
} | ||
|
||
public void findTask(String keyFind) { | ||
try { | ||
System.out.println("Here is what you are looking for: "); | ||
int count = 1; | ||
for (Task task : this.tasks) { | ||
if (task.getDescription().contains(keyFind)) { | ||
System.out.println(count + ". " + task); | ||
++count; | ||
} | ||
} | ||
} catch (IndexOutOfBoundsException e) { | ||
Ui.indexOutOfBoundsMessage(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package util; | ||
|
||
import tasks.Task; | ||
|
||
public class Ui { | ||
|
||
public static void greetingMessage() { | ||
System.out.println("Good evening. I'm Nocturne."); | ||
System.out.println("What ails you on this fine day?"); | ||
} | ||
|
||
public static void farewellMessage() { | ||
System.out.println("Farewell. And may the fortunes be ever in your favour."); | ||
} | ||
|
||
public static void indexOutOfBoundsMessage() { | ||
System.out.println("You are trying to access forbidden territory. Tread carefully."); | ||
} | ||
|
||
public static void emptyListMessage() { | ||
System.out.println("Your list is empty. Try again, when you have become more productive."); | ||
} | ||
|
||
public static void missingSlashMessage() { | ||
System.out.println("You are missing a /. Do not let this happen again."); | ||
} | ||
|
||
public static void printTask(Task task) { | ||
System.out.println(" " + task); | ||
} | ||
} |