Skip to content

Commit

Permalink
Completed branch-B-Snooze
Browse files Browse the repository at this point in the history
  • Loading branch information
limweijun committed Sep 10, 2022
1 parent 5c41549 commit 9437253
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
9 changes: 1 addition & 8 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
T|0|player
D|0|running|1998-10-03T18:00
T|0|runner
T|0|playerrrrrrrrr
T|0|runnn
T|0|readd
T|0|playyyy
T|0|eat
D|0|abc|2022-10-04T12:00
11 changes: 10 additions & 1 deletion src/main/java/Duke/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author LimWeiJun
*/
public class Deadline extends Task {
private final LocalDateTime by;
private LocalDateTime by;

/**
* The method takes in three parameters
Expand Down Expand Up @@ -53,4 +53,13 @@ public String getOriginalDetail() {
public String getFormattedDetail() {
return by.format(DateTimeFormatter.ofPattern("MMM dd yyyy HHmm"));
}

/**
* The method takes in a parameter
* @param newDateStr of type String
*/
@Override
public void updateDateTime(String newDateStr) {
this.by = LocalDateTime.parse(newDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
}
5 changes: 5 additions & 0 deletions src/main/java/Duke/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public String getOriginalDetail() {
public String getFormattedDetail() {
return at.format(DateTimeFormatter.ofPattern("MMM dd yyyy HHmm"));
}

@Override
void updateDateTime(String newDateStr) {
this.at = LocalDateTime.parse(newDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
}
13 changes: 13 additions & 0 deletions src/main/java/Duke/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ public void printDeleteSuccessfulMsg(Task task, int size) {
);
}

/**
* The method is a static and takes in two parameter
* @param task of type Task
* @param size of type int
*/
public void printUpdateSuccessfulMsg(Task task) {
Label dukeText = new Label("Kk. Updated:\n" + task.toString() +
"\nStop ordering me around");
dialogContainer.getChildren().add(
DialogBox.getDukeDialog(dukeText.getText(), new ImageView(dukeImage).getImage())
);
}

/**
* The method is a static and takes in a parameter
* @param task The input to be received
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/Duke/Parser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package Duke;

import java.util.ArrayList;
import java.util.Scanner;

/**
* The class make sense of the user command
Expand Down Expand Up @@ -29,7 +28,7 @@ public static void readLine(Ui ui, String command, TaskList tasks, MainWindow ma
}
} else if (strs.length == 2 && (strs[0].equals("delete"))) {
int index = Integer.parseInt(strs[1]) - 1;
tasks.delete(index);
tasks.deleteTask(index);
} else if (strs.length == 2 && (strs[0].equals("find"))) {
ArrayList<Task> tempTasks = new ArrayList<>();
for (int i = 0; i < tasks.getSize(); i++) {
Expand All @@ -38,6 +37,10 @@ public static void readLine(Ui ui, String command, TaskList tasks, MainWindow ma
}
}
mainWindow.printFindTasks(tempTasks);
} else if (strs.length == 5 && (strs[0].equals("update") && strs[1].equals("datetime"))) {
int index = Integer.parseInt(strs[2]) - 1;
String newDateStr = strs[3] + " " + strs[4];
tasks.updateTask(index, newDateStr);
} else {
try {
String[] details;
Expand All @@ -46,17 +49,17 @@ public static void readLine(Ui ui, String command, TaskList tasks, MainWindow ma
case "deadline":
details = command.split(" ", 2)[1].split(" /by ");
task = new Deadline(details[0], false, details[1]);
tasks.add(task);
tasks.addTask(task);
break;
case "event":
details = command.split(" ", 2)[1].split(" /at ");
task = new Event(details[0], false, details[1]);
tasks.add(task);
tasks.addTask(task);
break;
case "todo":
String detail = command.split(" ", 2)[1];
task = new Todo(detail, false);
tasks.add(task);
tasks.addTask(task);
break;
default:
mainWindow.printDontUnderstandMsg();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ public int getDone() {
abstract String getOriginalDetail();

abstract String getFormattedDetail();

abstract void updateDateTime(String newDateStr);
}
38 changes: 25 additions & 13 deletions src/main/java/Duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,37 @@ public TaskList(Ui ui, Storage storage, MainWindow mainWindow) {
* The method takes in a parameter
* @param task of type Task
*/
public void add(Task task) {
public void addTask(Task task) {
if (storage.updateFile(task)) {
tasks.add(task);
mainWindow.printAddSuccessfulMsg(task, tasks.size());
}
}

/**
* The method takes in a parameter of type int
* @param i of type int
*/
public void updateTask(int i, String newDateStr) {
Task task = tasks.get(i);
task.updateDateTime(newDateStr);
if (storage.rewriteEntireFile(tasks)) {
mainWindow.printUpdateSuccessfulMsg(task);
}
}

/**
* The method takes in a parameter of type int
* @param i of type int
*/
public void deleteTask(int i) {
Task task = tasks.get(i);
tasks.remove(i);
if (storage.rewriteEntireFile(tasks)) {
mainWindow.printDeleteSuccessfulMsg(task, tasks.size());
}
}

/**
* The method returns a variable of type int
* @return of type int
Expand Down Expand Up @@ -75,16 +99,4 @@ public void unMarkTaskAsDone(int i) {
mainWindow.printUnMarkTaskSuccessfulMsg(task);
}
}

/**
* The method takes in a parameter of type int
* @param i of type int
*/
public void delete(int i) {
Task task = tasks.get(i);
tasks.remove(i);
if (storage.rewriteEntireFile(tasks)) {
mainWindow.printDeleteSuccessfulMsg(task, tasks.size());
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/Duke/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public String getOriginalDetail() {
public String getFormattedDetail() {
return null;
}

@Override
void updateDateTime(String newDateStr) {

}
}

0 comments on commit 9437253

Please sign in to comment.