-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'jellywaiyan/master' into add-gradle-sup…
…port
- Loading branch information
Showing
26 changed files
with
787 additions
and
18 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
|
||
public class ByeCommand extends Command { | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
ui.byeMessage(); | ||
} | ||
|
||
public boolean running() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
|
||
public abstract class Command { | ||
public boolean running() { | ||
return true; | ||
} | ||
public abstract void execute(TaskList taskList, Ui ui, Storage storage); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
import Jelly.task.Deadline; | ||
|
||
public class DeadlineCommand extends Command { | ||
private String description; | ||
private String byWhen; | ||
|
||
public DeadlineCommand(String description, String byWhen) { | ||
this.description = description; | ||
this.byWhen = byWhen; | ||
} | ||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
Deadline deadlineTask = new Deadline(description, byWhen); | ||
taskList.add(deadlineTask); | ||
ui.addedTaskMessage(deadlineTask, taskList.size()); | ||
storage.saveAndExit(taskList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.exceptions.JellyBlankMessageException; | ||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
|
||
public class DeleteCommand extends Command { | ||
|
||
private int index; | ||
|
||
public DeleteCommand(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
if (index <= 0 || index > 100 || index > taskList.size()) { | ||
System.out.println("Invalid input"); | ||
} else if (taskList.get(index - 1) != null) { | ||
ui.deleteMessage(taskList.get(index - 1), taskList.size() - 1); | ||
taskList.delete(index - 1); | ||
} else { | ||
System.out.println("Invalid input"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
import Jelly.task.Event; | ||
|
||
public class EventCommand extends Command { | ||
|
||
private String description; | ||
|
||
private String fromWhen; | ||
|
||
private String toWhen; | ||
|
||
public EventCommand(String description, String fromWhen, String toWhen) { | ||
this.description = description; | ||
this.fromWhen = fromWhen; | ||
this.toWhen = toWhen; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
Event eventTask = new Event(description, fromWhen, toWhen); | ||
taskList.add(eventTask); | ||
ui.addedTaskMessage(eventTask, taskList.size()); | ||
storage.saveAndExit(taskList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
|
||
public class ListCommand extends Command { | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
ui.printList(taskList.getTasks()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.exceptions.JellyBlankMessageException; | ||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
|
||
public class MarkCommand extends Command { | ||
|
||
private int index; | ||
public MarkCommand(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
if (index <= 0 || index > 100) { | ||
System.out.println("Invalid input"); | ||
} else if (taskList.get(index - 1) != null) { | ||
if (taskList.get(index - 1).getTaskStatus() == "X") { | ||
System.out.println("Uh, it appears that you've finished this task o.o"); | ||
} else { | ||
taskList.get(index - 1).markAsDone(); | ||
System.out.println("Good job! I've marked this task as done :)"); | ||
} | ||
} else { | ||
System.out.println("Invalid input"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
import Jelly.task.Todo; | ||
|
||
public class ToDoCommand extends Command { | ||
private String description; | ||
|
||
public ToDoCommand(String description) { | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
Todo todoTask = new Todo(description); | ||
taskList.add(todoTask); | ||
|
||
ui.addedTaskMessage(todoTask, taskList.size()); | ||
storage.saveAndExit(taskList); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package Jelly.commands; | ||
|
||
import Jelly.exceptions.JellyBlankMessageException; | ||
import Jelly.main.Storage; | ||
import Jelly.main.TaskList; | ||
import Jelly.main.Ui; | ||
|
||
public class UnmarkCommand extends Command { | ||
|
||
public int index; | ||
|
||
public UnmarkCommand(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) { | ||
if (index <= 0 || index > 100) { | ||
System.out.println("Invalid input"); | ||
} else if (taskList.get(index - 1) != null) { | ||
if (taskList.get(index - 1).getTaskStatus() == " ") { | ||
System.out.println("Yo,you can't unmark something you haven't done yet o.o"); | ||
} else { | ||
taskList.get(index - 1).markAsUndone(); | ||
System.out.println("Bad job! I've marked this task as not done :("); | ||
} | ||
} else { | ||
System.out.println("Invalid input"); | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/Jelly/exceptions/JellyBlankMessageException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Jelly.exceptions; | ||
|
||
public class JellyBlankMessageException extends JellyException { | ||
public JellyBlankMessageException(String message) { | ||
super("Oops! " + message + " cannot be an empty task..."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Jelly.exceptions; | ||
|
||
public class JellyException extends Exception { | ||
public JellyException(String message) { | ||
super(message); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/Jelly/exceptions/JellyUnknownCommandException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Jelly.exceptions; | ||
|
||
|
||
public class JellyUnknownCommandException extends JellyException { | ||
public JellyUnknownCommandException() { | ||
super("Oops! I really don't know what you're saying :("); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package Jelly.main; | ||
|
||
import java.util.Scanner; | ||
import Jelly.commands.Command; | ||
import Jelly.exceptions.JellyException; | ||
|
||
|
||
public class Jelly { | ||
private static final String FILE_PATH = "./taskData/jelly.txt"; | ||
private final Scanner scanner = new Scanner(System.in); | ||
|
||
private TaskList taskList; | ||
private Ui ui; | ||
private Storage storage; | ||
|
||
private Jelly(String filePath) throws JellyException { | ||
this.storage = new Storage(filePath); | ||
this.ui = new Ui(); | ||
|
||
try { | ||
this.taskList = new TaskList(storage.startUp()); | ||
} catch (JellyException e) { | ||
this.taskList = new TaskList(); | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
public static void main(String[] args) throws JellyException { | ||
Jelly jelly = new Jelly(FILE_PATH); | ||
jelly.run(); | ||
} | ||
|
||
private void run() { | ||
ui.startUpMessage(); | ||
boolean running = true; | ||
while (running) { | ||
try { | ||
String command = ui.commandMe(); | ||
Command c = Parser.parse(command); | ||
c.execute(taskList, ui, storage); | ||
running = c.running(); | ||
} catch (JellyException e) { | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.