diff --git a/src/main/java/seedu/duke/command/ListCommand.java b/src/main/java/seedu/duke/command/ListCommand.java index a64a54280d..154936380d 100644 --- a/src/main/java/seedu/duke/command/ListCommand.java +++ b/src/main/java/seedu/duke/command/ListCommand.java @@ -1,20 +1,36 @@ -//package seedu.duke.command; +package seedu.duke.command; //import seedu.duke.storage.Storage; -//import seedu.duke.task.TaskList; -//import seedu.duke.ui.Ui; +//import seedu.duke.exception.DukeException; +import seedu.duke.exception.DukeException; +import seedu.duke.ui.Ui; +import seedu.duke.user.User; +import seedu.duke.user.UserList; + +import java.util.ArrayList; /** * Prints a list of all tasks to the user. */ -//public class ListCommand extends Command { +public class ListCommand extends Command { - //public ListCommand() { - //super(null); - //} + public ListCommand(String input) { + super(input); + } - //@Override - //public void execute(TaskList tasks, Ui ui/*, Storage storage*/) { - //ui.printList(tasks); - //} -//} + @Override + public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException { + String day = input.substring(1); + if (day.equals("all")) { + ui.printList(users, nowUser, "mon"); + ui.printList(users, nowUser, "tue"); + ui.printList(users, nowUser, "wed"); + ui.printList(users, nowUser, "thu"); + ui.printList(users, nowUser, "fri"); + ui.printList(users, nowUser, "sat"); + ui.printList(users, nowUser, "sun"); + } else { + ui.printList(users, nowUser, day); + } + } +} diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java index 3e0a86c7fb..b93279b4cc 100644 --- a/src/main/java/seedu/duke/parser/Parser.java +++ b/src/main/java/seedu/duke/parser/Parser.java @@ -7,7 +7,7 @@ //import seedu.duke.command.DoneCommand; //import seedu.duke.command.EventCommand; //import seedu.duke.command.FindCommand; -//import seedu.duke.command.ListCommand; +import seedu.duke.command.ListCommand; import seedu.duke.command.LogInCommand; import seedu.duke.exception.DukeException; @@ -17,7 +17,7 @@ public class Parser { //private static final String COMMAND_DEADLINE = "deadline"; //private static final String COMMAND_EVENT = "event"; - //private static final String COMMAND_LIST = "list"; + private static final String COMMAND_LIST = "list"; //private static final String COMMAND_DONE = "done"; //private static final String COMMAND_DELETE = "delete"; //private static final String COMMAND_FIND = "find"; @@ -42,8 +42,9 @@ public static Command parse(String input) throws DukeException { case COMMAND_EVENT: checkEventValidity(parsedInputs); return new EventCommand(parsedInputs[1]);*/ - /*case COMMAND_LIST: - return new ListCommand();*/ + case COMMAND_LIST: + checkListValidity(parsedInputs); + return new ListCommand(parsedInputs[1]); /*case COMMAND_DONE: checkTaskIndexValidity(parsedInputs); return new DoneCommand(parsedInputs[1]);*/ @@ -79,10 +80,15 @@ private static void checkAddValidity(String[] input) throws DukeException { throw new DukeException("There is no day in your add command!"); } else if (position[2].isEmpty()) { throw new DukeException("There is no time in your add command!"); - } else { + } else if (position[3].isEmpty()) { throw new DukeException("There is no location in your add command!"); - } + } + } + private static void checkListValidity(String[] input) throws DukeException { + if (input.length < 2) { + throw new DukeException("There is no description in your list command!"); + } } diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java index e180909393..8922d11dfc 100644 --- a/src/main/java/seedu/duke/ui/Ui.java +++ b/src/main/java/seedu/duke/ui/Ui.java @@ -1,11 +1,14 @@ package seedu.duke.ui; //import seedu.duke.task.Deadline; +import seedu.duke.exception.DukeException; import seedu.duke.task.Event; import seedu.duke.task.Task; import seedu.duke.task.TaskList; import seedu.duke.user.User; +import seedu.duke.user.UserList; +import java.util.ArrayList; import java.util.Scanner; /** @@ -52,18 +55,57 @@ public void showWelcome() { /** * Prints out all tasks saved in the array list. * - * @param taskList the array list to print. + * @param users the array list to print. */ - public void printList(TaskList taskList) { - if (taskList.getTotalTaskCount() > 0) { - System.out.println("Here are all the classes in your time table: "); + public void printList(UserList users, User nowUser, String day) throws DukeException { + int userIndex = -1; + + if (nowUser == null) { + throw new DukeException("Sorry! You are not logged in to any account :-("); + } + + for (int i = 0; i < users.getTotalUserCount(); i++) { + if ((users.getUser(i + 1).getName() == nowUser.getName())) { + userIndex = i + 1; + } + } + + ArrayList timetable = null; + switch (day) { + case "mon": + timetable = (users.getUser(userIndex).getTimetable()).getMonTimetable(); + break; + case "tue": + timetable = (users.getUser(userIndex).getTimetable()).getTueTimetable(); + break; + case "wed": + timetable = (users.getUser(userIndex).getTimetable()).getWedTimetable(); + break; + case "thu": + timetable = (users.getUser(userIndex).getTimetable()).getThuTimetable(); + break; + case "fri": + timetable = (users.getUser(userIndex).getTimetable()).getFriTimetable(); + break; + case "sat": + timetable = (users.getUser(userIndex).getTimetable()).getSatTimetable(); + break; + case "sun": + timetable = (users.getUser(userIndex).getTimetable()).getSunTimetable(); + break; + default: + throw new DukeException("Sorry! I don't know what day you mean :-("); + } + if (!timetable.isEmpty()) { int count = 1; - for (Task t : taskList.getTaskList()) { - System.out.println(count + ". " + t); + System.out.println("Here are the classes in your timetable for " + day + ":"); + for (Object u : timetable) { + System.out.println(count + ". " + u); count++; } + System.out.println(); } else { - System.out.println("There is no class in your time table! Consider adding one?"); + System.out.println("There is no class in your timetable for " + day + "!"); } }