Skip to content

Commit

Permalink
Revert "Add save task list to hard disk function"
Browse files Browse the repository at this point in the history
This reverts commit 7628ce8.
  • Loading branch information
ZhuLeYao committed Feb 12, 2023
1 parent 7628ce8 commit a2bef41
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 198 deletions.
6 changes: 2 additions & 4 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.util.List;

public class Deadline extends Task {
private final String taskType;
private final String taskDeadline;
Expand Down Expand Up @@ -38,8 +36,8 @@ public void printDeadlineTask() {
}

@Override
public void printDelete(List<Task> allTasks) {
int newTotalNumOfTasks = allTasks.size() - 1;
public void printDelete() {
int newTotalNumOfTasks = super.totalNumOfTasks - 1;
System.out.println("\t____________________________________________________________" +
"\n\t Noted. I've removed this task:" +
"\n\t " + this.taskType +
Expand Down
50 changes: 18 additions & 32 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -7,7 +6,7 @@ public class Duke {

Scanner sc = new Scanner(System.in);

public static void main(String[] args) throws DukeException, IOException {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
Expand All @@ -19,16 +18,16 @@ public static void main(String[] args) throws DukeException, IOException {
duke.chatDuke();
}

public void chatDuke() throws IOException {
public void chatDuke() {

Save save = new Save();
List<Task> allTasks = save.loadTxtFile();
List<Task> allTasks = new ArrayList<>();

this.printGreetingMessage();

boolean saidBye = false;
while (!saidBye) {
String command = sc.nextLine();

try {
if (command.equals("list")) {
this.printCommandList(allTasks);
Expand All @@ -44,24 +43,21 @@ public void chatDuke() throws IOException {
allTasks.size());
allTasks.set(taskIndex, todo);
todo.markAsDone();
save.saveListToFile(command, todo, allTasks);
} else if (oldTask.getTaskType().equals("[D]")) {
Deadline deadline = new Deadline(oldTask.getTaskNumber(),
true, oldTask.getTask(),
oldTask.getDeadline(), allTasks.size());
allTasks.set(taskIndex, deadline);
deadline.markAsDone();
save.saveListToFile(command, deadline, allTasks);
} else if (oldTask.getTaskType().equals("[E]")) {
Event event = new Event(oldTask.getTaskNumber(),
true, oldTask.getTask(),
oldTask.getEventStartTime(),
oldTask.getEventEndTime(), allTasks.size());
allTasks.set(taskIndex, event);
event.markAsDone();
save.saveListToFile(command, event, allTasks);
}
}else if (command.startsWith("unmark")) {
} else if (command.startsWith("unmark")) {
missingIndexException(command);
invalidIndexException(command, allTasks.size());
String[] str = command.split(" ");
Expand All @@ -73,22 +69,19 @@ public void chatDuke() throws IOException {
allTasks.size());
allTasks.set(taskIndex, todo);
todo.unmarkAsUndone();
save.saveListToFile(command, todo, allTasks);
} else if (oldTask.getTaskType().equals("[D]")) {
Deadline deadline = new Deadline(oldTask.getTaskNumber(),
false, oldTask.getTask(),
oldTask.getDeadline(), allTasks.size());
allTasks.set(taskIndex, deadline);
deadline.unmarkAsUndone();
save.saveListToFile(command, deadline, allTasks);
} else if (oldTask.getTaskType().equals("[E]")) {
Event event = new Event(oldTask.getTaskNumber(),
false, oldTask.getTask(),
oldTask.getEventStartTime(),
oldTask.getEventEndTime(), allTasks.size());
allTasks.set(taskIndex, event);
event.unmarkAsUndone();
save.saveListToFile(command, event, allTasks);
}
} else if (command.startsWith("todo")) {
emptyCommandException(command);
Expand All @@ -98,7 +91,6 @@ public void chatDuke() throws IOException {
taskName, allTasks.size() + 1);
allTasks.add(todo);
todo.printToDoTask();
save.saveListToFile(command, todo, allTasks);
} else if (command.startsWith("deadline")) {
emptyCommandException(command);
missingTimingException(command);
Expand All @@ -109,7 +101,6 @@ public void chatDuke() throws IOException {
taskName, taskDeadline, allTasks.size() + 1);
allTasks.add(deadline);
deadline.printDeadlineTask();
save.saveListToFile(command, deadline, allTasks);
} else if (command.startsWith("event")) {
emptyCommandException(command);
missingTimingException(command);
Expand All @@ -122,16 +113,14 @@ public void chatDuke() throws IOException {
taskName, eventStartTime, eventEndTime, allTasks.size() + 1);
allTasks.add(event);
event.printEventTask();
save.saveListToFile(command, event, allTasks);
} else if (command.startsWith("delete")) {
missingIndexException(command);
invalidIndexException(command, allTasks.size());
String[] str = command.split(" ");
int taskIndex = Integer.parseInt(str[1]) - 1;
Task task = allTasks.get(taskIndex);
task.printDelete(allTasks);
task.printDelete();
allTasks.remove(taskIndex);
save.saveListToFile(command, task, allTasks);
} else if (command.equals("bye")){
saidBye = true;
this.printByeMessage();
Expand All @@ -144,8 +133,6 @@ public void chatDuke() throws IOException {
System.out.println("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." +
"\n\t____________________________________________________________");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Expand Down Expand Up @@ -218,19 +205,18 @@ public void missingTimingException(String command) throws DukeException {
}

public void missingIndexException(String command) throws DukeException {
switch (command) {
case "mark":
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to mark a task as done cannot be empty." +
"\n\t____________________________________________________________");
case "unmark":
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." +
"\n\t____________________________________________________________");
case "delete":
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." +
"\n\t____________________________________________________________");
if (command.equals("mark")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to mark a task as done cannot be empty." +
"\n\t____________________________________________________________");
} else if (command.equals("unmark")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." +
"\n\t____________________________________________________________");
} else if (command.equals("delete")) {
throw new DukeException("\t____________________________________________________________" +
"\n\t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." +
"\n\t____________________________________________________________");
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.util.List;

class Event extends Task {
private final String taskType;
private final String eventStartTime;
Expand All @@ -19,7 +17,7 @@ public void markAsDone() {
"\n\t Nice! I've marked this task as done:\n" +
"\t " + this.taskType + "[X]" + " " + super.task +
" (from: " + this.eventStartTime + " to: "
+ this.eventEndTime + ")" +
+ this.eventEndTime +
"\n\t____________________________________________________________");
}

Expand All @@ -43,8 +41,8 @@ public void printEventTask() {
}

@Override
public void printDelete(List<Task> allTasks) {
int newTotalNumOfTasks = allTasks.size() - 1;
public void printDelete() {
int newTotalNumOfTasks = super.totalNumOfTasks - 1;
System.out.println("\t____________________________________________________________" +
"\n\t Noted. I've removed this task:" +
"\n\t " + this.taskType +
Expand Down
149 changes: 0 additions & 149 deletions src/main/java/Save.java

This file was deleted.

6 changes: 2 additions & 4 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import java.util.List;
public class Task {
protected final int taskNumber;
protected final boolean taskStatus;
Expand Down Expand Up @@ -26,12 +25,11 @@ public void unmarkAsUndone() {
"\n\t____________________________________________________________");
}

public void printDelete(List<Task> allTasks) {
int allTaskSize = allTasks.size() - 1;
public void printDelete() {
System.out.println("\t____________________________________________________________" +
"\n\t Noted. I've removed this task:" + "\n\t " +
this.getTaskStatus() + " " + this.task +
"\n\t Now you have " + allTaskSize + " tasks in the list.");
"\n\t Now you have " + this.totalNumOfTasks + " tasks in the list.");
}

public int getTaskNumber() {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.util.List;

class Todo extends Task {
private final String taskType;

Expand Down Expand Up @@ -33,8 +31,8 @@ public void printToDoTask() {
}

@Override
public void printDelete(List<Task> allTasks) {
int newTotalNumOfTasks = allTasks.size() - 1;
public void printDelete() {
int newTotalNumOfTasks = super.totalNumOfTasks - 1;
System.out.println("\t____________________________________________________________" +
"\n\t Noted. I've removed this task:" + "\n\t " + this.taskType +
super.getTaskStatus() + " " + super.task +
Expand Down

0 comments on commit a2bef41

Please sign in to comment.