-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Chen Jiehan] Duke Increments #362
base: master
Are you sure you want to change the base?
Changes from 113 commits
65f72a8
0112efe
cfd6da7
6e6ace1
edf8e35
ddaef0b
8249041
0600a98
4413d92
13b8591
769b127
a1fd1d8
4d80d71
68d6643
62e7419
86bfb0c
6881d44
ea0ad5e
92b4e16
dfded26
00bba16
876163f
b11c1a7
247ea35
e782c6e
7912df8
66cc53b
4290a0d
9008d34
558bd01
afd75d8
36e3558
5ef995e
d4c0bef
4daec44
4f3758e
f0d7e18
10b8524
ec81315
6ff5507
d3cefaa
8b4966e
656e9f6
dd39bb3
322cb82
352b017
5716618
da98b49
1307230
fad62f3
d5e69e2
54a8a50
e434d43
a114bcc
3233f26
e5b3ff5
e9d1ff1
e5f9a1e
a01bddc
483cac0
99dbc77
d16c6a9
3b22308
8485586
5b10689
44bfc14
8a857d9
385b9db
5b0f571
5d4a99d
15f5e14
36bb766
0bb979e
ac05a15
8f379ba
1549dc2
8617092
f9dcad8
f2ea70f
1b93ddc
dd1f236
9be4104
ba3183b
3a5cab1
d53b38a
c1dadb7
1f202de
1cd06f2
e5ea096
552686d
fc037a9
eb6abf7
c75971f
66153f2
500b483
aee1d67
e9ded6e
f7ea9e4
e085c39
673c164
29c1e9e
0874001
8038122
9528088
9ae7d3b
752a306
fb35ceb
c972bcb
dc02c20
67ca51d
335be23
81d6360
ea0f657
072bb1f
f98eb10
81112fc
04d981d
9d23054
b0a1494
faeff8a
8396d41
21eff20
b78a57b
288f22b
8983823
9eec2a9
b1f41cc
6295dbc
e0035da
d9dd7e2
e18cfca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import TaskList.Task; | ||
import Ui.Ui; | ||
|
||
import java.io.IOException; | ||
|
||
public class AddCommand extends Command { | ||
|
||
protected Task task; | ||
|
||
public AddCommand(Task task) { | ||
this.task = task; | ||
} | ||
|
||
/** | ||
* execute the command of adding task | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incomplete JavaDocs, should give clearer description. |
||
* @param taskList | ||
* @param ui | ||
* @param storage | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
taskList.addList(task); | ||
ui.showAddedMessage(taskList, task); | ||
storage.save(taskList); | ||
} | ||
|
||
/** | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing method description |
||
* @return boolean | ||
* | ||
*/ | ||
@Override | ||
public boolean isExit() { | ||
return isExit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
|
||
public class ByeCommand extends Command { | ||
|
||
public ByeCommand() {} | ||
|
||
@Override | ||
public void execute(TaskList t, Ui ui, Storage storage) { | ||
ui.showGoodbye(); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return isExit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
|
||
import java.io.IOException; | ||
|
||
public abstract class Command { | ||
|
||
protected boolean isExit = false; | ||
|
||
public Command() {} | ||
|
||
public abstract void execute(TaskList t, Ui ui, Storage storage) throws IOException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One suggestion is to allow this method to be overloaded, since not every command will require all 3 parameters to be used. |
||
|
||
public abstract boolean isExit(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, the name of the method should not be the same as the variable name |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
|
||
import java.io.IOException; | ||
|
||
public class DeleteCommand extends Command { | ||
|
||
private int taskNo; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable naming could be clearer, something like |
||
|
||
public DeleteCommand(int taskNo) { | ||
this.taskNo = taskNo; | ||
} | ||
|
||
/** | ||
* execute the command of deleting the task | ||
* @param taskList | ||
* @param ui | ||
* @param storage | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
ui.showDeleteMessage(taskList, taskList.list.get(taskNo - 1)); | ||
taskList.delete(taskNo); | ||
storage.save(taskList); | ||
} | ||
|
||
/** | ||
* check if it is exited | ||
* @return boolean | ||
*/ | ||
@Override | ||
public boolean isExit() { | ||
return isExit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
|
||
import java.io.IOException; | ||
|
||
public class DoneCommand extends Command { | ||
|
||
private int taskNo; | ||
|
||
public DoneCommand(int taskNo) { | ||
this.taskNo = taskNo; | ||
} | ||
|
||
/** | ||
* execute the command of marking a task as done | ||
* @param taskList | ||
* @param ui | ||
* @param storage | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
taskList.list.get(taskNo - 1).markAsDone(); | ||
ui.showDoneMessage(taskList.list.get(taskNo - 1)); | ||
storage.save(taskList); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return isExit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
import TaskList.Task; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class FindCommand extends Command{ | ||
private String word; | ||
|
||
public FindCommand(String word) { | ||
this.word = word; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
ui.showFindMessage(taskList.contains(word)); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return false; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package Command; | ||
|
||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
|
||
import java.io.IOException; | ||
|
||
public class ListCommand extends Command { | ||
|
||
public ListCommand() { | ||
} | ||
|
||
/** | ||
* execute the command of listing out all the task | ||
* @param taskList | ||
* @param ui | ||
* @param storage | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
ui.showListMessage(taskList); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return isExit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,59 @@ | ||
import Command.Command; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has incorrect indentation level, plus multiple lines of unnecessary newlines. |
||
import Parser.Parser; | ||
import Storage.Storage; | ||
import TaskList.TaskList; | ||
import Ui.Ui; | ||
|
||
import java.io.IOException; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
private Storage storage; | ||
private TaskList tasks; | ||
private Ui ui; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fields pertaining to Duke such as Storage, TaskList and Ui should be declared outside the main method block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is due to the incorrect indentation level |
||
public Duke(String filePath) { | ||
ui = new Ui(); | ||
storage = new Storage(filePath); | ||
try { | ||
tasks = new TaskList(storage.load()); | ||
} catch (IOException e) { | ||
ui.showLoadingError(); | ||
tasks = new TaskList(); | ||
} | ||
} | ||
|
||
public void run() { | ||
ui.showWelcome(); | ||
boolean isExit = false; | ||
while (!isExit) { | ||
try { | ||
String fullCommand = ui.readCommand(); | ||
ui.showLine(); // show the divider line ("_______") | ||
Command c = Parser.parse(fullCommand); | ||
c.execute(tasks, ui, storage); | ||
isExit = c.isExit(); | ||
} catch (IOException e) { | ||
ui.showError(e.getMessage()); | ||
} finally { | ||
ui.showLine(); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File path should be one that is accessible with reference to duke as the root file, rather than your C: Drive |
||
new Duke("/Users/jhchen/Documents/GitHub/duke/src/main/java/duke.txt").run(); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package Duke; | ||
|
||
public class DukeException extends Exception { | ||
public DukeException(String s) { | ||
super(s); | ||
} | ||
|
||
public DukeException() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package Parser; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has incorrect indentation level, and the end of the file should have one newline character for Git |
||
|
||
import TaskList.Deadlines; | ||
import TaskList.Events; | ||
import TaskList.ToDos; | ||
import Command.Command; | ||
import Command.AddCommand; | ||
import Command.ByeCommand; | ||
import Command.DeleteCommand; | ||
import Command.DoneCommand; | ||
import Command.ListCommand; | ||
import Command.FindCommand; | ||
|
||
public class Parser { | ||
public Parser() {} | ||
|
||
/** | ||
* Parse in the full command and return the command accordingly | ||
* @param fullCommand | ||
* @return Command | ||
*/ | ||
public static Command parse(String fullCommand) { | ||
int i = fullCommand.indexOf(' '); | ||
String first = getFirstWord(fullCommand); | ||
switch (first) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switch case indentation is off. Case should be aligned with switch, according to Java Coding Standard documentation. |
||
case "delete": | ||
return new DeleteCommand(Integer.parseInt(fullCommand.substring(i + 1))); | ||
case "done": | ||
return new DoneCommand(Integer.parseInt(fullCommand.substring(i + 1))); | ||
case "list": | ||
return new ListCommand(); | ||
case "bye": | ||
return new ByeCommand(); | ||
case "find": | ||
return new FindCommand(fullCommand.substring((i + 1))); | ||
case "todo": | ||
if (fullCommand.length() == 4) { | ||
System.out.println("OOPS!!! The description of a todo cannot be empty."); | ||
} else { | ||
ToDos taskTodo = new ToDos(fullCommand.substring(i + 1)); | ||
taskTodo.setTaskType("T"); | ||
return new AddCommand(taskTodo); | ||
} | ||
case "deadline": | ||
int j = fullCommand.indexOf("/"); | ||
int k = fullCommand.indexOf(" "); | ||
|
||
if (fullCommand.length() == 8) { | ||
System.out.println("OOPS!!! The description of a deadline cannot be empty."); | ||
} else { | ||
Deadlines taskDeadline = new Deadlines(fullCommand.substring(k + 1, j - 1)); | ||
taskDeadline.setTime(fullCommand.substring(j + 4)); | ||
taskDeadline.setTaskType("D"); | ||
return new AddCommand(taskDeadline); | ||
} | ||
case "event": | ||
int p = fullCommand.indexOf("/"); | ||
int q = fullCommand.indexOf(" "); | ||
|
||
if (fullCommand.length() == 5) { | ||
System.out.println("OOPS!!! The description of an event cannot be empty."); | ||
} else { | ||
Events taskEvent = new Events(fullCommand.substring(q + 1, p - 1)); | ||
taskEvent.setTime(fullCommand.substring(p + 4)); | ||
taskEvent.setTaskType("E"); | ||
return new AddCommand(taskEvent); | ||
} | ||
default: | ||
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-()"); | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* to get the first word in a string of input | ||
* @param input | ||
* @return String | ||
*/ | ||
public static String getFirstWord(String input) { | ||
if (input.indexOf(" ") > -1) { | ||
return input.substring(0, input.indexOf(" ")); | ||
} else { | ||
return input; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Package naming should begin with small letter to avoid conflict with names of classes or interfaces.