Skip to content

Commit

Permalink
Completed A-Assertions, A-CodeQuality
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiHawkEye committed Sep 11, 2019
1 parent de9f79b commit ead332a
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 224 deletions.
12 changes: 4 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Application class for Duke.
*/
public class Duke {
private static final String SAVE_PATH = "data/duke.txt";

private Storage storage;
private TaskList tasks;
private Ui ui;
Expand All @@ -19,7 +21,7 @@ public class Duke {
* Constructor of Duke class without parameters.
*/
public Duke() {
this("data/duke.txt");
this(SAVE_PATH);
}

/**
Expand All @@ -44,7 +46,7 @@ public Duke(String filePath) {
* @param args Arguments entered when main method is executed.
*/
public static void main(String[] args) {
Duke duke = new Duke("data/duke.txt");
Duke duke = new Duke(SAVE_PATH);
duke.run();
}

Expand All @@ -61,12 +63,6 @@ public String getResponse(String input) {
* Run method of Duke.
*/
public void run() {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
this.ui.showWelcome();

boolean isExit = false;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

/**
* Controller for MainWindow. Provides the layout for the other controls.
*/
Expand Down
29 changes: 7 additions & 22 deletions src/main/java/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@
* Command containing method for adding Task to TaskList.
*/
public class AddCommand extends Command {
/**
* Constructor for AddCommand without parameters.
*/
public AddCommand() {
this("");
}
private Task task;

/**
* Constructor for AddCommand with String parameter.
* Constructor for AddCommand.
*
* @param fullCommand Input entered by user.
* @param task Task to be added.
*/
public AddCommand(String fullCommand) {
this.fullCommand = fullCommand;
public AddCommand(Task task) {
this.task = task;
}

/**
* Returns an AddCommand as initialized by the constructor.
*
* @param fullCommand Input entered by user.
*/
public Command clone(String fullCommand) {
return new AddCommand(fullCommand);
}

/**
* Adds a Task to the TaskList.
*
Expand All @@ -44,10 +30,9 @@ public Command clone(String fullCommand) {
* @param storage Storage that stores the modified TaskList.
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
Task task = Parser.parseTask(this.fullCommand);
tasks.add(task);
tasks.add(this.task);
ui.printResponse("Got it. I've added this task:\n "
+ task.toString() + "\n"
+ this.task.toString() + "\n"
+ "Now you have " + tasks.size() + " tasks in the list.");
}

Expand Down
10 changes: 0 additions & 10 deletions src/main/java/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
* interacting with TaskList, Ui and Storage objects based on input.
*/
public abstract class Command {
protected String fullCommand;

/**
* Public method to initialize Command objects.
*
* @param fullCommand Input entered by user.
* @return Command object initialized by constructor.
*/
public abstract Command clone(String fullCommand);

/**
* Interacts with TaskList, Ui and Storage objects based on input.
*
Expand Down
29 changes: 7 additions & 22 deletions src/main/java/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,15 @@
* Command containing method for deleting Task from TaskList.
*/
public class DeleteCommand extends Command {
/**
* Constructor for DeleteCommand without parameters.
*/
public DeleteCommand() {
this("");
}
private int itemId;

/**
* Constructor for DeleteCommand with String parameter.
*
* @param fullCommand Input entered by user.
*/
public DeleteCommand(String fullCommand) {
this.fullCommand = fullCommand;
}

/**
* Returns a DeleteCommand as initialized by the constructor.
* Constructor for DeleteCommand.
*
* @param fullCommand Input entered by user.
* @param itemId Id of item to be deleted.
*/
public Command clone(String fullCommand) {
return new DeleteCommand(fullCommand);
public DeleteCommand(int itemId) {
this.itemId = itemId;
}

/**
Expand All @@ -44,14 +30,13 @@ public Command clone(String fullCommand) {
* @param storage Storage that stores the modified TaskList.
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
int itemId = Parser.parseDelete(this.fullCommand);
try {
Task item = tasks.remove(itemId);
Task item = tasks.remove(this.itemId);
ui.printResponse("Noted. I've removed this task: \n "
+ item.toString() + "\n"
+ "Now you have " + tasks.size() + " tasks in the list.");
} catch (IndexOutOfBoundsException e) {
throw new DukeException("☹ OOPS!!! There is no item " + itemId + ".");
throw new DukeException("☹ OOPS!!! There is no item " + this.itemId + ".");
}
}

Expand Down
29 changes: 7 additions & 22 deletions src/main/java/command/DoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@
* Command containing method for marking Task from TaskList as done.
*/
public class DoneCommand extends Command {
/**
* Constructor for DoneCommand without parameters.
*/
public DoneCommand() {
this("");
}
private int itemId;

/**
* Constructor for DoneCommand with String parameter.
* Constructor for DoneCommand.
*
* @param fullCommand Input entered by user.
* @param itemId Id of item to be marked done.
*/
public DoneCommand(String fullCommand) {
this.fullCommand = fullCommand;
public DoneCommand(int itemId) {
this.itemId = itemId;
}

/**
* Returns a DoneCommand as initialized by the constructor.
*
* @param fullCommand Input entered by user.
*/
public Command clone(String fullCommand) {
return new DoneCommand(fullCommand);
}

/**
* Marks a Task from the TaskList as done.
*
Expand All @@ -44,14 +30,13 @@ public Command clone(String fullCommand) {
* @param storage Storage that stores the modified TaskList.
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
int itemId = Parser.parseDone(this.fullCommand);
try {
tasks.markAsDone(itemId);
tasks.markAsDone(this.itemId);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("☹ OOPS!!! There is no item " + itemId + ".");
}
ui.printResponse("Nice! I've marked this task as done: \n "
+ tasks.get(itemId).toString());
+ tasks.get(this.itemId).toString());
}

/**
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,6 @@
* Command containing method for exiting program.
*/
public class ExitCommand extends Command {
/**
* Constructor for ExitCommand without parameters.
*/
public ExitCommand() {
this("");
}

/**
* Constructor for ExitCommand with String parameter.
*
* @param fullCommand Input entered by user.
*/
public ExitCommand(String fullCommand) {
this.fullCommand = fullCommand;
}

/**
* Returns an ExitCommand as initialized by the constructor.
*
* @param fullCommand Input entered by user.
*/
public Command clone(String fullCommand) {
return new ExitCommand(fullCommand);
}

/**
* Exits program.
*
Expand Down
27 changes: 6 additions & 21 deletions src/main/java/command/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@
* Command containing method for finding Tasks in TaskList.
*/
public class FindCommand extends Command {
/**
* Constructor for FindCommand without parameters.
*/
public FindCommand() {
this("");
}
private String query;

/**
* Constructor for DeleteCommand with String parameter.
* Constructor for FindCommand.
*
* @param fullCommand Input entered by user.
* @param query Query to be matched.
*/
public FindCommand(String fullCommand) {
this.fullCommand = fullCommand;
public FindCommand(String query) {
this.query = query;
}

/**
* Returns a FindCommand as initialized by the constructor.
*
* @param fullCommand Input entered by user.
*/
public Command clone(String fullCommand) {
return new FindCommand(fullCommand);
}

/**
* Finds Tasks from the TaskList that matches the query.
*
Expand All @@ -45,9 +31,8 @@ public Command clone(String fullCommand) {
*/
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
TaskList tempList = new TaskList();
String query = Parser.parseFind(this.fullCommand);
for (Task task : tasks) {
if (task.toString().contains(query)) {
if (task.toString().contains(this.query)) {
tempList.add(task);
}
}
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,6 @@
* Command containing method for listing Tasks in TaskList.
*/
public class ListCommand extends Command {
/**
* Constructor for ListCommand without parameters.
*/
public ListCommand() {
this("");
}

/**
* Constructor for ListCommand with String parameter.
*
* @param fullCommand Input entered by user.
*/
public ListCommand(String fullCommand) {
this.fullCommand = fullCommand;
}

/**
* Returns a ListCommand as initialized by the constructor.
*
* @param fullCommand Input entered by user.
*/
public Command clone(String fullCommand) {
return new ListCommand(fullCommand);
}

/**
* List Tasks in TaskList.
*
Expand Down
Binary file modified src/main/java/data/duke.txt
Binary file not shown.
Binary file modified src/main/java/duke/Duke.class
Binary file not shown.
Binary file modified src/main/java/duke/MainWindow.class
Binary file not shown.
Binary file modified src/main/java/duke/command/AddCommand.class
Binary file not shown.
Binary file modified src/main/java/duke/command/Command.class
Binary file not shown.
Binary file modified src/main/java/duke/command/DeleteCommand.class
Binary file not shown.
Binary file modified src/main/java/duke/command/DoneCommand.class
Binary file not shown.
Binary file modified src/main/java/duke/command/ExitCommand.class
Binary file not shown.
Binary file modified src/main/java/duke/command/FindCommand.class
Binary file not shown.
Binary file modified src/main/java/duke/command/ListCommand.class
Binary file not shown.
Binary file modified src/main/java/duke/util/Parser.class
Binary file not shown.
Binary file modified src/main/java/duke/util/Storage.class
Binary file not shown.
Binary file modified src/main/java/duke/util/Ui.class
Binary file not shown.
Loading

0 comments on commit ead332a

Please sign in to comment.