Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2021S1#30 from manuelmanuntag96/manue…
Browse files Browse the repository at this point in the history
…l-Feature1

Manuel feature1
  • Loading branch information
yeapcl authored Oct 9, 2020
2 parents 6eff529 + ddc01bc commit 7bb136a
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 68 deletions.
15 changes: 11 additions & 4 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package seedu.duke;

import seedu.duke.command.Command;
import seedu.duke.exception.DukeException;
//import seedu.duke.storage.Storage;
import seedu.duke.parser.Parser;
import seedu.duke.task.TaskList;
import seedu.duke.ui.Ui;
import seedu.duke.command.Command;
import seedu.duke.parser.Parser;
import seedu.duke.user.User;
import seedu.duke.user.UserList;

//import seedu.duke.storage.Storage;

public class Duke {

//private Storage storage;
private TaskList tasks;
private UserList users;
private final Ui ui;

public Duke() {
Expand All @@ -22,17 +26,20 @@ public Duke() {
ui.showError(e.getMessage());
tasks = new TaskList();
}*/
users = new UserList();
}

public void run() {
ui.showWelcome();
boolean isExit = false;
User currentUser = null;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(tasks, ui/*, storage*/);
c.execute(users, ui/*, storage*/);
currentUser = c.getCurrentUser();
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
Expand Down
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.UserList;

/**
* Terminates Duke program.
Expand All @@ -14,7 +15,7 @@ public ByeCommand() {
}

//@Override
public void execute(TaskList tasks, Ui ui/*, Storage storage*/) {
public void execute(UserList users, Ui ui/*, Storage storage*/) {
isExit = true;
ui.showBye();
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
//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;

public abstract class Command {
protected String input;
protected boolean isExit = false;
protected User currentUser;

/**
* Creates a new command.
Expand All @@ -21,13 +24,17 @@ public Command(String input) {
/**
* Executes the Command based on the TaskList, Ui and Storage.
*
* @param tasks the TaskList given to execute command on.
* @param users the UserList given to execute command on.
* @param ui the corresponding messages based on the task.
* @throws DukeException if execution encounters error.
*/
public abstract void execute(TaskList tasks, Ui ui/*, Storage storage*/) throws DukeException;
public abstract void execute(UserList users, Ui ui/*, Storage storage*/) throws DukeException;

public boolean isExit() {
return isExit;
}

public User getCurrentUser() {
return currentUser;
}
}
34 changes: 17 additions & 17 deletions src/main/java/seedu/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package seedu.duke.command;
//package seedu.duke.command;

import seedu.duke.exception.DukeException;
//import seedu.duke.exception.DukeException;
//import seedu.duke.storage.Storage;
import seedu.duke.task.Task;
import seedu.duke.task.TaskList;
import seedu.duke.ui.Ui;
//import seedu.duke.task.Task;
//import seedu.duke.task.TaskList;
//import seedu.duke.ui.Ui;

/**
* Deletes a task from the task list.
*/
public class DeleteCommand extends Command {
//public class DeleteCommand extends Command {

public DeleteCommand(String information) {
super(information);
}
//public DeleteCommand(String information) {
//super(information);
//}

@Override
public void execute(TaskList tasks, Ui ui/*, Storage storage*/) throws DukeException {
int index = Integer.parseInt(input);
Task removedTask = tasks.getTask(index);
tasks.deleteTask(index);
ui.printDelete(tasks, removedTask);
//@Override
//public void execute(TaskList tasks, Ui ui/*, Storage storage*/) throws DukeException {
//int index = Integer.parseInt(input);
//Task removedTask = tasks.getTask(index);
//tasks.deleteTask(index);
//ui.printDelete(tasks, removedTask);
//storage.write(tasks);
}
}
//}
//}
38 changes: 19 additions & 19 deletions src/main/java/seedu/duke/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package seedu.duke.command;
//package seedu.duke.command;

//import seedu.duke.storage.Storage;
import seedu.duke.task.Task;
import seedu.duke.task.TaskList;
import seedu.duke.ui.Ui;
//import seedu.duke.task.Task;
//import seedu.duke.task.TaskList;
//import seedu.duke.ui.Ui;

/**
* Finds task(s) in task list that matches the keyword.
*/
public class FindCommand extends Command {
//public class FindCommand extends Command {

public FindCommand(String keyword) {
super(keyword);
}
//public FindCommand(String keyword) {
//super(keyword);
//}

@Override
public void execute(TaskList tasks, Ui ui/*, Storage storage*/) {
TaskList tasksFound = new TaskList();
for (Task t : tasks.getTaskList()) {
if (t.getDescription().contains(input)) {
tasksFound.addTask(t);
}
}
ui.printFind(tasksFound, input);
}
}
//@Override
//public void execute(TaskList tasks, Ui ui/*, Storage storage*/) {
//TaskList tasksFound = new TaskList();
//for (Task t : tasks.getTaskList()) {
//if (t.getDescription().contains(input)) {
//tasksFound.addTask(t);
//}
//}
//ui.printFind(tasksFound, input);
//}
//}
24 changes: 12 additions & 12 deletions src/main/java/seedu/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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.task.TaskList;
//import seedu.duke.ui.Ui;

/**
* 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() {
//super(null);
//}

@Override
public void execute(TaskList tasks, Ui ui/*, Storage storage*/) {
ui.printList(tasks);
}
}
//@Override
//public void execute(TaskList tasks, Ui ui/*, Storage storage*/) {
//ui.printList(tasks);
//}
//}
29 changes: 29 additions & 0 deletions src/main/java/seedu/duke/command/LogInCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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.ui.Ui;
import seedu.duke.user.User;
import seedu.duke.user.UserList;

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

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

@Override
public void execute(UserList users, Ui ui/*, 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);
//storage.write(tasks);
}
}
42 changes: 32 additions & 10 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import seedu.duke.command.ByeCommand;
import seedu.duke.command.Command;
import seedu.duke.command.DeleteCommand;
//import seedu.duke.command.DeleteCommand;
//import seedu.duke.command.DoneCommand;
//import seedu.duke.command.EventCommand;
import seedu.duke.command.FindCommand;
import seedu.duke.command.ListCommand;
//import seedu.duke.command.FindCommand;
//import seedu.duke.command.ListCommand;
import seedu.duke.command.LogInCommand;
import seedu.duke.exception.DukeException;

/**
Expand All @@ -15,11 +16,13 @@
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";
//private static final String COMMAND_DELETE = "delete";
//private static final String COMMAND_FIND = "find";
private static final String COMMAND_BYE = "bye";
private static final String COMMAND_LOGIN = "login";


/**
* Returns a Command object based on user's string input.
Expand All @@ -37,24 +40,29 @@ 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:
return new ListCommand();*/
/*case COMMAND_DONE:
checkTaskIndexValidity(parsedInputs);
return new DoneCommand(parsedInputs[1]);*/
case COMMAND_DELETE:
/*case COMMAND_DELETE:
checkTaskIndexValidity(parsedInputs);
return new DeleteCommand(parsedInputs[1]);
case COMMAND_FIND:
verifyFind(parsedInputs);
return new FindCommand(parsedInputs[1]);
return new FindCommand(parsedInputs[1]);*/
case COMMAND_LOGIN:
checkLogInValidity(parsedInputs);
return new LogInCommand(parsedInputs[1]);
case COMMAND_BYE:
return new ByeCommand();
default:
throw new DukeException("Sorry! I don't know what that means :-(");
}
}



/**
* Checks the index's validity.
*
Expand Down Expand Up @@ -123,6 +131,20 @@ private static void checkEventValidity(String[] input) throws DukeException {
}
}

private static void checkLogInValidity(String[] input) throws DukeException {
if (input.length < 2) {
throw new DukeException("There is no description in your login command!");
} else if (!input[1].contains("/")) {
throw new DukeException("An login requires an '/' to indicate password!");
}
int atPosition = input[1].indexOf("/");
if (input[1].substring(0, atPosition).isBlank()) {
throw new DukeException("There is no username in your login command!");
} else if (input[1].substring(atPosition + 1).isBlank()) {
throw new DukeException("An login requires a password!");
}
}

/**
* Checks the validity of the KEYWORD for find.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package s.d.timetable;
package seedu.duke.timetable;

import java.util.ArrayList;

Expand Down
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 @@ -4,6 +4,7 @@
//import seedu.duke.task.Event;
import seedu.duke.task.Task;
import seedu.duke.task.TaskList;
import seedu.duke.user.User;

import java.util.Scanner;

Expand Down Expand Up @@ -129,6 +130,10 @@ public void showBye() {
System.out.println("Thanks for using WhereGotTime. Hope to see you again soon!");
}

public void greetUser(User currentUser) {
System.out.println("Hello " + currentUser.getName() + "!");
}

/**
* Prints error message.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package s.d.user;
package seedu.duke.user;

import s.d.timetable.Timetable;
import seedu.duke.timetable.Timetable;

public class User {
protected String name;
Expand All @@ -12,4 +12,12 @@ public User(String name, String passWord) {
this.passWord = passWord;
this.timetable = new Timetable();
}

public String getName() {
return name;
}

public Timetable getTimetable() {
return timetable;
}
}
Loading

0 comments on commit 7bb136a

Please sign in to comment.