package seedu.address.logic.commands;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.UnmodifiableObservableList;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.task.ReadOnlyTask;
import seedu.address.model.task.UniqueTaskList.TaskNotFoundException;

/**
 * Deletes a task identified using it's last displayed index from the list
 */
public class DeleteCommand extends Command {

    public static final String COMMAND_WORD = "delete";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Deletes the task identified by the index number used in the last task listing.\n"
            + "Parameters: INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " 1";

    public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task: %1$s";

    public final int targetIndex;

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


    @Override
    public CommandResult execute() throws CommandException {

        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        ReadOnlyTask taskToDelete = lastShownList.get(targetIndex - 1);

        try {
            model.deleteTask(taskToDelete);
        } catch (TaskNotFoundException pnfe) {
            assert false : "The target task cannot be missing";
        }

        return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
    }

}

@@ -70,143 +70,34 @@
 ore.
-Messages;%0Aimport seedu.address.commons.core.UnmodifiableObservableList;%0Aimport seedu.address.logic.commands.exceptions.CommandException
+UnmodifiableObservableList
 ;%0Aim
@@ -881,17 +881,16 @@
 %0A    %7D%0A%0A
-%0A
     @Ove
@@ -933,32 +933,8 @@
 te()
- throws CommandException
  %7B%0A%0A
@@ -1094,80 +1094,42 @@
     
-throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX
+System.out.println(%22invalid index%22
 );%0A 
@@ -1382,32 +1382,439 @@
 ing%22;%0A        %7D%0A
+        %0A%0A        assert model != null;%0A        try %7B%0A            int indexRemoved = model.deleteTask(taskToDelete);%0A            model.getUndoStack().push(COMMAND_WORD);%0A            model.getDeletedStackOfTasks().push(taskToDelete);%0A            model.getDeletedStackOfTasksIndex().push(indexRemoved);%0A        %7D catch (TaskNotFoundException tnfe) %7B%0A            System.out.println(%22Task not found%22);%0A        %7D
 %0A        return 

Update DeleteCommand.java