Skip to content

Commit

Permalink
make changes according to reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
greyguy21 committed Sep 16, 2021
1 parent 600abff commit 8ad6f62
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 176 deletions.
5 changes: 4 additions & 1 deletion src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke;

import duke.command.Command;
import duke.data.TaskList;
import duke.exception.DukeException;
import duke.parser.Parser;
Expand Down Expand Up @@ -46,7 +47,9 @@ public TaskList getTaskList() {

public String getResponse(String input) {
try{
return parser.parse(input);
Command command = parser.parse(input);
return command.execute(this.taskList, this.ui, this.storage);

} catch (DukeException e) {
return e.getError();
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/duke/command/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.ui.Ui;

public class ByeCommand extends Command {
final static String cmd = "bye";
final static String usage = "exit app";
final static String format = "bye";

public ByeCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
return ui.showBye();
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
51 changes: 12 additions & 39 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
package duke.command;

import duke.data.TaskList;
import duke.exception.*;
import duke.storage.Storage;
import duke.ui.Ui;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Stores description of usage and format of command.
*/
public class Command {
String cmd;
String fn;
String format;
public abstract class Command {

/**
* Constructs Command object
*
* @param cmd command
* @param fn description of usage
* @param format format
*/
public Command(String cmd, String fn, String format) {
this.cmd = cmd;
this.fn = fn;
this.format = format;
}

/**
* Returns command
*
* @return command
*/
public String getCmd() {
return this.cmd;
}
public Command() {}

/**
* Returns description of usage
*
* @return description of usage
*/
public String getFn() {
return this.fn;
}

/**
* Returns format
*
* @return format
*/
public String getFormat() {
return this.format;
}
public abstract String execute(TaskList tasks, Ui ui, Storage storage);
}
44 changes: 44 additions & 0 deletions src/main/java/duke/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.task.Deadline;
import duke.ui.Ui;

import java.time.LocalDateTime;

public class DeadlineCommand extends Command {
final static String cmd = "deadline";
final static String usage = "add tasks that need to be done before a specific date & time";
final static String format = "deadline {task name} /by {yyyy-MM-dd HH:mm}";

private String name;
private LocalDateTime by;

public DeadlineCommand(String name, LocalDateTime by) {
this.name = name;
this.by = by;
}

public DeadlineCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
Deadline deadline = new Deadline(name, by);
tasks.addTask(deadline);
storage.updateData(tasks);
return ui.showTaskAdded(deadline, tasks.getSize());
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
40 changes: 40 additions & 0 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.task.Task;
import duke.ui.Ui;

public class DeleteCommand extends Command {
final static String cmd = "delete";
final static String usage = "deletes specified task";
final static String format = "delete {task number}";

private int taskNum;

public DeleteCommand(int taskNum) {
this.taskNum = taskNum;
}

public DeleteCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
Task task = tasks.getTask(taskNum);
tasks.deleteTask(task);
storage.updateData(tasks);
return ui.showTaskDeleted(task, tasks.getSize());
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
40 changes: 40 additions & 0 deletions src/main/java/duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.task.Task;
import duke.ui.Ui;

public class DoneCommand extends Command {
final static String cmd = "done";
final static String usage = "marks specified task as done";
final static String format = "done {task number}";

private int taskNum;

public DoneCommand(int taskNum) {
this.taskNum = taskNum;
}

public DoneCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
Task task = tasks.getTask(this.taskNum);
task.markAsDone();
storage.updateData(tasks);
return ui.showTaskDone(task);
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
44 changes: 44 additions & 0 deletions src/main/java/duke/command/EventCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.task.Event;
import duke.ui.Ui;

import java.time.LocalDateTime;

public class EventCommand extends Command {
final static String cmd = "event";
final static String usage = "add tasks that need that starts at a specific time";
final static String format = "event {task name} /by {yyyy-MM-dd HH:mm}";

private String name;
private LocalDateTime at;

public EventCommand(String name, LocalDateTime at) {
this.name = name;
this.at = at;
};

public EventCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
Event event = new Event(name, at);
tasks.addTask(event);
storage.updateData(tasks);
return ui.showTaskAdded(event, tasks.getSize());
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
37 changes: 37 additions & 0 deletions src/main/java/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.ui.Ui;

public class FindCommand extends Command {
final static String cmd = "find";
final static String usage = "find a task by searching for a keyword";
final static String format = "find {keyword}";

private String keyword;

public FindCommand(String keyword) {
this.keyword = keyword;
}

public FindCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
TaskList t = tasks.matchTasks(keyword);
return ui.showTaskList(t, "find");
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
30 changes: 30 additions & 0 deletions src/main/java/duke/command/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package duke.command;

import duke.data.TaskList;
import duke.storage.Storage;
import duke.ui.Ui;

public class HelpCommand extends Command {
final static String cmd = "help";
final static String usage = "shows list of all commands & usages";
final static String format = "help";

public HelpCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
return ui.showAfterHelp();
}

public static String getCmd() {
return cmd;
}

public static String getUsage() {
return usage;
}

public static String getFormat() {
return format;
}
}
21 changes: 21 additions & 0 deletions src/main/java/duke/command/InvalidCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package duke.command;

import duke.data.TaskList;
import duke.exception.DukeException;
import duke.exception.InvalidEntryException;
import duke.storage.Storage;
import duke.ui.Ui;

public class InvalidCommand extends Command {

public InvalidCommand() {}

@Override
public String execute(TaskList tasks, Ui ui, Storage storage) {
try {
throw new InvalidEntryException("error");
} catch (DukeException e) {
return e.getError();
}
}
}
Loading

0 comments on commit 8ad6f62

Please sign in to comment.