Skip to content

Commit

Permalink
add snooze extension
Browse files Browse the repository at this point in the history
  • Loading branch information
yingqi0607 committed Sep 18, 2020
1 parent 8f38e48 commit 6ad1551
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
T|✘|buy bread
T|✘|go school
E|✘|dating|2020-09-08
D|✘|sad|2023-09-08
D|✘|sad|2020-07-09
T|✘|buy book
D|✘|return nook|2020-09-08
D|✘|return book|2020-07-09
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.time.format.DateTimeFormatter;
public class Deadline extends Task{

protected LocalDate by;
public LocalDate by;

/**
* Deadline constructor
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public static Command parse(String input) throws DukeException{
case "bye":
command = new ExitCommand();
break;
case "snooze":
if(input.length() == 6){
throw new DukeException("☹ OOPS!!! You cannot leave descriptions of a snooze empty");
} else {
taskIndex = Integer.parseInt(commandline[1]);
command = new SnoozeCommand(taskIndex, LocalDate.parse(commandline[2]));
}
break;

default:
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/SnoozeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.time.LocalDate;

public class SnoozeCommand extends Command{

public int taskIndex;
public LocalDate newDate;

public SnoozeCommand(int taskIndex, LocalDate newDate){
super();
this.taskIndex = taskIndex;
this.newDate = newDate;
}

/**
* Execute the command
* @param inputTasks the list of tasks used
* @param storage the storage used
*/
public void execute(TaskList inputTasks, Storage storage, Ui ui){
assert taskIndex > 0;
inputTasks.snooze(taskIndex, newDate, ui);
storage.writeToFile(inputTasks);
}
}
18 changes: 18 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.time.LocalDate;
public class TaskList {
public ArrayList<Task> tasks;

Expand Down Expand Up @@ -86,4 +88,20 @@ public void findKeyword(String keyword, Ui ui){
ui.addResponse(listNum.toString() + "." + keyTasks.get(i).toString());
}
}

public void snooze(int taskIndex, LocalDate newDate, Ui ui){
if(tasks.get(taskIndex - 1) instanceof Deadline){
Deadline editedTask = new Deadline(tasks.get(taskIndex - 1).description, newDate);
tasks.set(taskIndex - 1, editedTask);
ui.addResponse("Okay! You have snoozed task " + taskIndex + " to " +
newDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")));
}else if(tasks.get(taskIndex - 1) instanceof Event){
Event editedTask = new Event(tasks.get(taskIndex - 1).description, newDate);
tasks.set(taskIndex - 1, editedTask);
ui.addResponse("Okay! You have snoozed task " + taskIndex + " to " +
newDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")));
}else{
ui.addResponse("This task do not need to be snoozed");
}
}
}

0 comments on commit 6ad1551

Please sign in to comment.