Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2021S1#40 from weisiong24/weisiong-Fe…
Browse files Browse the repository at this point in the history
…ature2

LGTM!
  • Loading branch information
yeapcl authored Oct 10, 2020
2 parents 7bb136a + 3803066 commit 80722f3
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 26 deletions.
12 changes: 9 additions & 3 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.duke;

import seedu.duke.command.AddCommand;
import seedu.duke.command.Command;
import seedu.duke.command.LogInCommand;
import seedu.duke.exception.DukeException;
import seedu.duke.parser.Parser;
import seedu.duke.task.TaskList;
Expand Down Expand Up @@ -32,14 +34,18 @@ public Duke() {
public void run() {
ui.showWelcome();
boolean isExit = false;
User currentUser = null;
User nowUser = null;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(users, ui/*, storage*/);
currentUser = c.getCurrentUser();
c.execute(users, ui, nowUser/*, storage*/);

if (c.isLogIn() == true) {
nowUser = c.getCurrentUser();
}
//System.out.println(nowUser.getName());
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/seedu/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package seedu.duke.command;

import seedu.duke.exception.DukeException;
//import seedu.duke.storage.Storage;
import seedu.duke.task.Event;
import seedu.duke.task.TaskList;
import seedu.duke.timetable.Timetable;
import seedu.duke.ui.Ui;
import seedu.duke.user.User;
import seedu.duke.user.UserList;

/**
* Adds an event to the task list.
*/
public class AddCommand extends Command {

public AddCommand(String input) {
super(input);
}

@Override
public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException {
//Lec /day /time /location
if (nowUser != null) {
String[] parsedInputs = input.split(" /", 4);
String[] timeInputs = parsedInputs[2].split("-", 2);

String date = parsedInputs[1];

for (int i = 0; i < users.getTotalUserCount(); i++) {
if ((users.getUser(i + 1).getName() == nowUser.getName())) {
Event newEvent = new Event(parsedInputs[0], parsedInputs[3], timeInputs[0], timeInputs[1]);
ui.printEvent(newEvent, date);
switch (date) {
case "mon":
(users.getUser(i + 1).getTimetable()).getMonTimetable().add(newEvent);
break;
case "tue":
(users.getUser(i + 1).getTimetable()).getTueTimetable().add(newEvent);
break;
case "wed":
(users.getUser(i + 1).getTimetable()).getWedTimetable().add(newEvent);
break;
case "thu":
(users.getUser(i + 1).getTimetable()).getThuTimetable().add(newEvent);;
break;
case "fri":
(users.getUser(i + 1).getTimetable()).getFriTimetable().add(newEvent);
break;
case "sat":
(users.getUser(i + 1).getTimetable()).getSatTimetable().add(newEvent);
break;
case "sun":
(users.getUser(i + 1).getTimetable()).getSunTimetable().add(newEvent);
break;
default:
throw new DukeException("Sorry! I don't know what day you mean :-(");
}
}
}
//((Timetable) currentUser.getTimetable())
//tasks.addTask(newTask);
//ui.printEvent(newEvent, date);
//storage.write(tasks);
} else {
throw new DukeException("Sorry! You are not Logged in to any account :-(");
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/seedu/duke/command/ByeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//import seedu.duke.storage.Storage;
import seedu.duke.task.TaskList;
import seedu.duke.ui.Ui;
import seedu.duke.user.User;
import seedu.duke.user.UserList;

/**
Expand All @@ -15,7 +16,7 @@ public ByeCommand() {
}

//@Override
public void execute(UserList users, Ui ui/*, Storage storage*/) {
public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) {
isExit = true;
ui.showBye();
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/seedu/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public abstract class Command {
protected String input;
protected boolean isExit = false;
protected User currentUser;
protected User currentUser = null;
protected boolean isLogIn = false;

/**
* Creates a new command.
Expand All @@ -28,7 +29,7 @@ public Command(String input) {
* @param ui the corresponding messages based on the task.
* @throws DukeException if execution encounters error.
*/
public abstract void execute(UserList users, Ui ui/*, Storage storage*/) throws DukeException;
public abstract void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException;

public boolean isExit() {
return isExit;
Expand All @@ -37,4 +38,8 @@ public boolean isExit() {
public User getCurrentUser() {
return currentUser;
}

public boolean isLogIn() {
return isLogIn;
}
}
5 changes: 4 additions & 1 deletion src/main/java/seedu/duke/command/LogInCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ public LogInCommand(String input) {
}

@Override
public void execute(UserList users, Ui ui/*, Storage storage*/) throws DukeException {
public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException {
String[] parsedInputs = input.split(" /", 2);
User newUser = new User(parsedInputs[0], parsedInputs[1]);
currentUser = newUser;
users.addUser(newUser);
ui.greetUser(newUser);
isLogIn = true;


//storage.write(tasks);
}
}
35 changes: 29 additions & 6 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.duke.parser;

import seedu.duke.command.AddCommand;
import seedu.duke.command.ByeCommand;
import seedu.duke.command.Command;
//import seedu.duke.command.DeleteCommand;
Expand All @@ -22,6 +23,7 @@ public class Parser {
//private static final String COMMAND_FIND = "find";
private static final String COMMAND_BYE = "bye";
private static final String COMMAND_LOGIN = "login";
private static final String COMMAND_ADD = "add";


/**
Expand Down Expand Up @@ -54,13 +56,34 @@ public static Command parse(String input) throws DukeException {
case COMMAND_LOGIN:
checkLogInValidity(parsedInputs);
return new LogInCommand(parsedInputs[1]);
case COMMAND_ADD:
checkAddValidity(parsedInputs);
return new AddCommand(parsedInputs[1]);
case COMMAND_BYE:
return new ByeCommand();
default:
throw new DukeException("Sorry! I don't know what that means :-(");
}
}

private static void checkAddValidity(String[] input) throws DukeException {
if (input.length < 2) {
throw new DukeException("There is no description in your add command!");
} else if (!input[1].contains("/")) {
throw new DukeException("An add command needs to be in a 'name /day /time /location' format!");
}
String[] position = input[1].split(" /",4);
if (position[0].isEmpty()) {
throw new DukeException("There is no name in your add command!");
} else if (position[1].isEmpty()) {
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 {
throw new DukeException("There is no location in your add command!");
}

}


/**
Expand Down Expand Up @@ -104,9 +127,9 @@ private static void checkDeadlineValidity(String[] input) throws DukeException {
throw new DukeException("A deadline task requires a '/by' to indicate time frame!");
}
int byPosition = input[1].indexOf("/by");
if (input[1].substring(0, byPosition).isBlank()) {
if (input[1].substring(0, byPosition).isEmpty()) {
throw new DukeException("There is no description in your deadline command!");
} else if (input[1].substring(byPosition + 3).isBlank()) {
} else if (input[1].substring(byPosition + 3).isEmpty()) {
throw new DukeException("Please indicate time frame!");
}
}
Expand All @@ -124,9 +147,9 @@ private static void checkEventValidity(String[] input) throws DukeException {
throw new DukeException("An event task requires an '/at' to indicate location!");
}
int atPosition = input[1].indexOf("/at");
if (input[1].substring(0, atPosition).isBlank()) {
if (input[1].substring(0, atPosition).isEmpty()) {
throw new DukeException("There is no description in your event command!");
} else if (input[1].substring(atPosition + 3).isBlank()) {
} else if (input[1].substring(atPosition + 3).isEmpty()) {
throw new DukeException("An event task requires an '/at' to indicate location!");
}
}
Expand All @@ -138,9 +161,9 @@ private static void checkLogInValidity(String[] input) throws DukeException {
throw new DukeException("An login requires an '/' to indicate password!");
}
int atPosition = input[1].indexOf("/");
if (input[1].substring(0, atPosition).isBlank()) {
if (input[1].substring(0, atPosition).isEmpty()) {
throw new DukeException("There is no username in your login command!");
} else if (input[1].substring(atPosition + 1).isBlank()) {
} else if (input[1].substring(atPosition + 1).isEmpty()) {
throw new DukeException("An login requires a password!");
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/seedu/duke/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ public Event(String description, String location, String timeStart, String timeE
//setTaskType("E");
}

/**
* Returns the event detail of the task.
* @return the event detail of the task.
*/
/*public String getAt() {
//return at;
}*/

@Override
public String toString() {
return super.toString();
return description + " " + location + " " + " " + timeStart + "-" + timeEnd;
}
}
33 changes: 33 additions & 0 deletions src/main/java/seedu/duke/timetable/Timetable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package seedu.duke.timetable;

import seedu.duke.task.Event;

import java.util.ArrayList;
import java.util.List;

public class Timetable {
protected ArrayList<Object> monTimetable;
Expand All @@ -20,4 +23,34 @@ public Timetable() {
this.satTimetable = new ArrayList<>();
this.sunTimetable = new ArrayList<>();
}

public ArrayList<Object> getMonTimetable() {
return monTimetable;
}

public ArrayList<Object> getTueTimetable() {
return tueTimetable;
}

public ArrayList<Object> getWedTimetable() {
return wedTimetable;
}

public ArrayList<Object> getThuTimetable() {
return thuTimetable;
}

public ArrayList<Object> getFriTimetable() {
return friTimetable;
}

public ArrayList<Object> getSatTimetable() {
return satTimetable;
}

public ArrayList<Object> getSunTimetable() {
return sunTimetable;
}


}
13 changes: 7 additions & 6 deletions src/main/java/seedu/duke/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.duke.ui;

//import seedu.duke.task.Deadline;
//import seedu.duke.task.Event;
import seedu.duke.task.Event;
import seedu.duke.task.Task;
import seedu.duke.task.TaskList;
import seedu.duke.user.User;
Expand Down Expand Up @@ -81,14 +81,15 @@ public void printList(TaskList taskList) {
/**
* Prints out the event task given by the user.
*
* @param task the task to be added to the array list.
* @param event the task to be added to the array list.
*/
/*public void printEvent(TaskList taskList, Event task) {
System.out.println("Got it! I've added the following event in the list:\n" + task);
System.out.println("Now now have " + taskList.getTotalTaskCount() + " tasks in the list.");
}*/
public void printEvent(Event event, String date) {
System.out.println("Got it! I've added the following event in " + date + "\n" + event);
//System.out.println("Now now have " + taskList.getTotalTaskCount() + " tasks in the list.");
}

public void printDone(Task task) {

System.out.println("Nice! I have marked this task as done:\n" + task);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/user/UserList.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public User getUser(int index) throws DukeException {
try {
return users.get(index - 1);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Invalid task number! Type 'list' to get an overview of your tasks.");
throw new DukeException("Invalid user number!");
}
}

Expand Down
2 changes: 1 addition & 1 deletion text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
login John Snow /123123
bye
bye

0 comments on commit 80722f3

Please sign in to comment.