Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2021S1#49 from yeapcl/branch-yeapcl-e…
Browse files Browse the repository at this point in the history
…ditFeature

Added Feature 3: Edit
  • Loading branch information
yeapcl authored Oct 14, 2020
2 parents e8c901a + 14d235d commit 105edcb
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/seedu/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ public AddCommand(String input) {
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[] parsedInputs = input.split("/", 5);
String[] timeInputs = parsedInputs[3].split("-", 2);

String day = parsedInputs[1].toLowerCase();
String day = parsedInputs[2].toLowerCase().trim();

for (int i = 0; i < users.getTotalUserCount(); i++) {
if ((users.getUser(i + 1).getName().equals(nowUser.getName()))) {
Event newEvent = new Event(parsedInputs[0], parsedInputs[3], timeInputs[0], timeInputs[1]);
Event newEvent = new Event(parsedInputs[1].trim(), parsedInputs[4].trim(),
timeInputs[0].trim(), timeInputs[1].trim());
ui.printEvent(newEvent, day);
(users.getUser(i + 1).getTimetable()).getTimetable(day).add(newEvent);
users.getUser(i + 1).getTimetable().getTimetable(day).add(newEvent);
}
}
//((Timetable) currentUser.getTimetable())
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/seedu/duke/command/EditCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.duke.command;

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

import java.util.ArrayList;

public class EditCommand extends Command {
public EditCommand(String input) {
super(input);
}

@Override
public void execute(UserList users, Ui ui, User nowUser/*, Storage storage*/) throws DukeException {
String[] parsedInputs = input.split("/", 4);
String date = parsedInputs[1].trim();
String[] newTime = parsedInputs[3].split("-");
int index = Integer.parseInt(parsedInputs[2].trim());
Event oldEvent;

for (int i = 0; i < users.getTotalUserCount(); i++) {
if ((users.getUser(i + 1).getName().equals(nowUser.getName()))) {
oldEvent = nowUser.getTimetable().getTimetable(date).get(index - 1);
Event newEvent = new Event(oldEvent.getDescription(), oldEvent.getLocation(), newTime[0], newTime[1]);
nowUser.getTimetable().getTimetable(date).set(index - 1, newEvent);
ui.printEdit(newTime, date, index);
}
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.duke.command.CompareCommand;
import seedu.duke.command.Command;
import seedu.duke.command.DeleteCommand;
import seedu.duke.command.EditCommand;
//import seedu.duke.command.DoneCommand;
//import seedu.duke.command.EventCommand;
//import seedu.duke.command.FindCommand;
Expand All @@ -28,6 +29,7 @@ public class Parser {
private static final String COMMAND_BYE = "bye";
private static final String COMMAND_LOGIN = "login";
private static final String COMMAND_ADD = "add";
private static final String COMMAND_EDIT = "edit";
private static final String COMMAND_COMPARE = "compare";


Expand Down Expand Up @@ -68,6 +70,9 @@ public static Command parse(String input) throws DukeException {
case COMMAND_ADD:
checkAddValidity(parsedInputs);
return new AddCommand(parsedInputs[1]);
case COMMAND_EDIT:
//checkEditValidity(parsedInputs);
return new EditCommand(parsedInputs[1]);
case COMMAND_BYE:
return new ByeCommand();
case COMMAND_COMPARE:
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/duke/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ public String getTimeStart() {
public String getTimeEnd() {
return this.timeEnd;
}

public String getLocation() {
return this.location;
}

}
5 changes: 5 additions & 0 deletions src/main/java/seedu/duke/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public void printFind(TaskList taskList, String keyword) {
}
}

public void printEdit(String[] editedField, String date, int index) throws DukeException {
System.out.println("Got it! I have edited " + date + "'s #" + index + " lesson to "
+ "the following timing: " + editedField[0] + "-" + editedField[1]);
}

/**
* Prints farewell message.
*/
Expand Down

0 comments on commit 105edcb

Please sign in to comment.