Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2021S1#42 from tammykoh/master
Browse files Browse the repository at this point in the history
Feature 4: List
  • Loading branch information
yeapcl authored Oct 11, 2020
2 parents 80722f3 + bddf625 commit 510a59b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 25 deletions.
40 changes: 28 additions & 12 deletions src/main/java/seedu/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
18 changes: 12 additions & 6 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
Expand All @@ -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]);*/
Expand Down Expand Up @@ -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!");
}
}


Expand Down
56 changes: 49 additions & 7 deletions src/main/java/seedu/duke/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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<Object> 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 + "!");
}
}

Expand Down

0 comments on commit 510a59b

Please sign in to comment.