Skip to content
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

[Natalie Tan] Duke Increments #344

Open
wants to merge 96 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum Aug 6, 2019
0112efe
Add sample checkstyle configuration
j-lum Aug 12, 2019
cfd6da7
Change file mode on `gradle` to be executable
j-lum Aug 18, 2019
6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum Aug 18, 2019
a3ca5a4
Add configuration for console applications
j-lum Aug 20, 2019
7b60e81
Merge pull request #13 from j-lum/javaexec
j-lum Aug 21, 2019
2327b2a
complete Level-1
nattanyz Aug 29, 2019
791010a
add to process method, create DukeBot and TaskList classes
nattanyz Aug 29, 2019
070f7e5
encapsulate logic in DukeBot class, implement Level-2
nattanyz Aug 29, 2019
d497040
add Task class, implement Level-3
nattanyz Aug 29, 2019
17493be
add TaskType enum, welcomeMessage, and minor changes to comments
nattanyz Aug 29, 2019
f84bf53
modify process() method (incomplete)
nattanyz Aug 30, 2019
6bb6adf
implement Level-4, Level-5 and A-Exceptions
nattanyz Sep 2, 2019
6a07612
implement Level-6, add deleteTask() method to TaskList class
nattanyz Sep 5, 2019
b1e9465
Merge branch 'gradle'
nattanyz Sep 5, 2019
7e6ed3a
merge branch 'gradle'
nattanyz Sep 5, 2019
070a1e2
start to implement gson for Level-7
nattanyz Sep 5, 2019
148f51b
create Command, Parser, Storage, Ui classes and remove DukeBot class …
nattanyz Sep 6, 2019
54e6458
create and update classes for each type of Command with working imple…
nattanyz Sep 6, 2019
8eafe91
something's wrong :(
nattanyz Sep 6, 2019
06492d2
remove no-longer-used processInput method in TaskList class, implemen…
nattanyz Sep 8, 2019
d89a23a
place java files in packages
nattanyz Sep 8, 2019
94dcf1c
add DukeTest.java, modify build.gradle to support JUnit
nattanyz Sep 9, 2019
13c1f9b
remove unnecessary iterators and replace unnecessary references to "t…
nattanyz Sep 9, 2019
72d92b2
add newTask method to separate creating and adding of tasks, remove a…
nattanyz Sep 9, 2019
de6b351
partially implement load() and save() methods in Storage class using …
nattanyz Sep 9, 2019
0d7e28e
resolve main class not found issue, change command classes to use ui.…
nattanyz Sep 27, 2019
82c5a39
build jar file, add "command not recognised" error message
nattanyz Sep 27, 2019
a0ae06d
attempt to implement datetime
nattanyz Sep 27, 2019
7043555
implement execute() in abstract class AddTaskCommand, implement creat…
nattanyz Sep 29, 2019
ce6a15d
create DukeException class and ExceptionType enum to handle different…
nattanyz Sep 29, 2019
901c014
identify need for error handling when user enters "todo" without anyt…
nattanyz Sep 29, 2019
51e41e5
implement proper exception handling, abstract commonalities of AddTod…
nattanyz Sep 29, 2019
404874b
Merge pull request #6 from nattanyz/branch-Level-8
nattanyz Sep 29, 2019
0dca0c2
Merge branch 'master' of https://github.com/nattanyz/duke
nattanyz Sep 29, 2019
7cffc25
FINALLY, FINALLY implemented Level-7
nattanyz Sep 29, 2019
3413d6b
move exception-related classes to util.exception, add UiMessage enum …
nattanyz Sep 29, 2019
3988b1d
update gitignore to ignore data files
nattanyz Sep 29, 2019
66a1ab5
remove Storage param from execute() method, remove Gson from build.gr…
nattanyz Sep 29, 2019
f3fbba2
add TaskType enum to use in Task and related classes, remove redundan…
nattanyz Sep 29, 2019
003af61
add and edit JavaDoc for all Command classes and Enums
nattanyz Sep 29, 2019
dd6a241
begin to implement Snooze command
nattanyz Sep 29, 2019
b308c14
add ModifyTaskCommand class to simplify implementations of Done, Snoo…
nattanyz Sep 29, 2019
98d1395
implement C-Priority
nattanyz Sep 29, 2019
3034767
refactor: rename Deadline, Todo and Event to DeadlineTask, TodoTask a…
nattanyz Sep 29, 2019
94dd6d4
move parseDate() to DateTime class, change implementations of Deadlin…
nattanyz Sep 29, 2019
b744f1d
implement snoozeDate() and snooze() methods
nattanyz Sep 29, 2019
8b3d7c6
new jar file for v0.2
nattanyz Sep 29, 2019
a89e491
configure build.gradle for JavaFX and install SceneBuilder
nattanyz Sep 29, 2019
8d0aa67
follow GUI setup tutorial, original application is not broken (yay!)
nattanyz Sep 30, 2019
c6e12d8
manage to compile and run, opens GUI window
nattanyz Sep 30, 2019
3ecafbf
change images to png (but still cannot get them to appear)
nattanyz Sep 30, 2019
e4fd3fc
wrap TextField and Button in HBox
nattanyz Sep 30, 2019
6bfa580
rectify MainWindow fit
nattanyz Sep 30, 2019
6c84fec
refactor: move GUI-related classes to duke.gui, add title and applica…
nattanyz Sep 30, 2019
d9b9f4d
fix scrolling and resizing behaviour of MainWindow, add some JavaDoc
nattanyz Sep 30, 2019
eaaf797
refactor: organise methods in Duke class
nattanyz Sep 30, 2019
97eaa87
replace Ui class with Ui interface and Cli and Gui implementations, a…
nattanyz Sep 30, 2019
be0d50f
continue refactoring in earlier commit
nattanyz Sep 30, 2019
d5daa2d
create CliDuke and GuiDuke classes to implement Duke interface, set d…
nattanyz Sep 30, 2019
64b49d2
refactor: rename DialogBox to MessageBox.add ColourScheme enum to tak…
nattanyz Sep 30, 2019
2b12109
fix VBox width issue, complete refactoring of dialogBox to messageBox
nattanyz Sep 30, 2019
4ed6113
complete refactoring from previous commit, add GREY colour scheme
nattanyz Sep 30, 2019
6608006
partially implement GUI using messageBoxQueue. changed font family an…
nattanyz Sep 30, 2019
95db334
use ui.showMessage() in Storage class, add try/catch blocks to debug,…
nattanyz Sep 30, 2019
da470b7
add Storage param back to execute() method in all Commands, add stora…
nattanyz Sep 30, 2019
427b3d6
add DukeMessageBox, ExceptionMessageBox, TaskMessageBox and UserMessa…
nattanyz Sep 30, 2019
ed3a65a
add showUserInput() method to Gui class
nattanyz Sep 30, 2019
8505aa5
remove System.out.println statements. add SaveCommand
nattanyz Sep 30, 2019
68257c5
Merge pull request #7 from nattanyz/branch-Level-10
nattanyz Sep 30, 2019
aff5481
Merge branch 'master' of https://github.com/nattanyz/duke into branch…
nattanyz Sep 30, 2019
95fc0ad
remove redundant print statements in Task class, change filePath for …
nattanyz Sep 30, 2019
506bd56
Merge pull request #8 from nattanyz/branch-Level-10
nattanyz Sep 30, 2019
ae70f07
Merge branch 'master' of https://github.com/nattanyz/duke
nattanyz Sep 30, 2019
a988fae
begin writing readme
nattanyz Sep 30, 2019
a9e589d
remove external readme file
nattanyz Sep 30, 2019
5720d80
resize images in readme
nattanyz Sep 30, 2019
52bf5a7
edits to readme
nattanyz Sep 30, 2019
9725820
complete readme
nattanyz Sep 30, 2019
cd2608c
add assertions, fix some UI messages, remove redundant spaces
nattanyz Sep 30, 2019
434af83
change application mainClassName in build.gradle, resize images in re…
nattanyz Sep 30, 2019
77f0894
Set theme jekyll-theme-cayman
nattanyz Sep 30, 2019
e6bd017
move screenshots to docs/images folder, publish GitHub pages
nattanyz Sep 30, 2019
39f4004
add ui.png to docs
nattanyz Sep 30, 2019
6a0dbab
refactor: rename Duke to Dose
nattanyz Sep 30, 2019
5d1b9ae
add HelpCommand
nattanyz Sep 30, 2019
f44e942
add TaskTest
nattanyz Sep 30, 2019
cad088e
add UiMessageTest
nattanyz Sep 30, 2019
e960263
Merge pull request #9 from nattanyz/branch-Tests-and-Assertions
nattanyz Sep 30, 2019
a1c9980
Merge branch 'master' of https://github.com/nattanyz/duke into branch…
nattanyz Sep 30, 2019
d57ad03
Merge branch 'branch-Tests-and-Assertions'
nattanyz Sep 30, 2019
9f14515
fix broken image in readme, update build.gradle to build new jar
nattanyz Sep 30, 2019
711cb9b
fix text wrap, new v1.3 jar
nattanyz Sep 30, 2019
7ea9ef2
final fix for text wrap, redo v1.3 jar
nattanyz Sep 30, 2019
538e85a
temporarily remove ui.png to fix naming
nattanyz Oct 2, 2019
8f03955
add renamed ui.png file
nattanyz Oct 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Deadline extends Task {
private String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
this.type = "D";

}

@Override
public String toString() {
return super.toString() + "(by: " + by + ")";
}
}
12 changes: 6 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import java.util.Scanner;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed


public class Duke {
private static DukeBot dukeBot;

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
dukeBot = new DukeBot();
dukeBot.initialise();
}
}
53 changes: 53 additions & 0 deletions src/main/java/DukeBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class DukeBot {
private Scanner in;
private TaskList taskList = new TaskList();
private static final String welcomeMessage = "What can I do for you?";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the coding standard:

Constant names must be all uppercase using underscore to separate words.


/**
* Starts DukeBot and prints welcome message.
*/

public void initialise() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code should be in the constructor and run can be a public method that can be called separately IMO.

String logo = " ____ _ \n"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be a constant too.

+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println(welcomeMessage);
in = new Scanner(System.in);
run();
}

/**
* Reads input from the user and passes it to process().
*/
private void run() {
String input; // stores input from user

this.taskList = new TaskList();

// continuously take in user input until terminated
while (in.hasNextLine()) {
input = in.nextLine();
if (input.equals("bye")) {
// if "bye", terminate
// todo: is there a way to combine this into processInput()?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can make processInput return a boolean to indicate whether the command is "bye"

break;
}

try {
this.taskList.processInput(input);
} catch (InputMismatchException e) {
System.out.println("Sorry! I don't know what that means :(");
}
}

// say goodbye upon exit
System.out.println("Bye. Hope to see you again soon!");
}
}
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task {
private String at;

public Event(String description, String at) {
super(description);
this.at = at;
this.type = "E";
}

@Override
public String toString() {
return super.toString() + "(at: " + at + ")";
}
}
27 changes: 27 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Task {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this class should be static :)

private String description;
private Boolean isDone;
protected String type;

public Task(String description) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this constructor should take in type as a parameter as well because type is declared in this class.

this.description = description;
this.isDone = false;
}

@Override
public String toString() {
String type = "[" + this.type + "] ";
String status = "[" + this.getStatusIcon() + "] ";
return type + status + this.description;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); // return tick or X symbols
}

public void markAsDone() {
this.isDone = true;
System.out.println("Nice! I've marked this task as done:");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User interaction should be handled at the call site. Otherwise, it would be difficulty to integrate with GUI.

System.out.println(this.toString());
}
}
124 changes: 124 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class TaskList {

private ArrayList<Task> tasks = new ArrayList<>();

public enum TaskType {
DEADLINE,
EVENT,
TODO
}

public void addToList(TaskType taskType, String description, String deadline)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this method take in a Task and construct the Task at the call site. This reduces duplicate code.

throws IllegalArgumentException {
Task newTask = null; // task to be added

// based on task type, create corresponding subclass object
switch (taskType) {
case DEADLINE:
newTask = new Deadline(description, deadline);
break;
case EVENT:
newTask = new Event(description, deadline);
break;
case TODO:
newTask = new Todo(description);
break;
default:
// this should not happen; invalid task type should be caught in caller method already
System.out.println("Something went wrong!");
break;
}

// add newTask to taskList
tasks.add(newTask);
System.out.println("Okay! I've added: " + description
+ ". Use list to see all your tasks!");
// todo: description has trailing space due to using /at or /by as delimiter. how?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strip(), stripLeading(), stripTrailing(), whichever that suits your need :)

}

public void printList() {
int i = 1;
for (Iterator<Task> iterator = this.tasks.iterator(); iterator.hasNext(); i++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the iterator here is necessary :)

String s = iterator.next().toString();
System.out.println(i + ". " + s);
}
}

public Task getTask(int taskIndex) throws IndexOutOfBoundsException {
return tasks.get(taskIndex - 1);
}

/**
* Processes the given input string.
*
* @param input input string given by user.
*/
public void processInput(String input) throws InputMismatchException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having almost all the app logic here, maybe it would help to define a Command class and a few subclasses like AddCommand, DoneCommand, etc. It would make the code more maintainable.

Scanner inputReader = new Scanner(input);
String command = inputReader.next();
String description;
String deadline;

switch (command) {
case "list":
// if "list", print list
this.printList();
break;
case "done":
try {
int taskId = inputReader.nextInt(); // extract the task ID entered by user
this.getTask(taskId).markAsDone(); // mark task as done
} catch (InputMismatchException e) {
// user input after "done" is not an int
System.out.println("Oops! You entered an invalid task ID!");
} catch (NoSuchElementException e) {
// user input after "done" is blank
System.out.println("Oops! You did not enter a task ID!");
} catch (IndexOutOfBoundsException e) {
// user input after "done" is an invalid task ID
System.out.println("Oops! You entered an invalid task ID!");
}
break;
case "todo":
try {
description = inputReader.nextLine();
deadline = "no deadline";
this.addToList(TaskList.TaskType.TODO, description, deadline);
} catch (NoSuchElementException e) {
// user imput after task type is blank
System.out.println("Oops! You did not enter a description!");
}
break;
case "event":
inputReader.useDelimiter("/at");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty neat :)

try {
description = inputReader.next();
deadline = inputReader.next();
this.addToList(TaskList.TaskType.EVENT, description, deadline);
} catch (NoSuchElementException e) {
// user imput after task type is blank
System.out.println("Oops! You did not enter a description or deadline!");
}
break;
case "deadline":
inputReader.useDelimiter("/by");
try {
description = inputReader.next();
deadline = inputReader.next();
this.addToList(TaskList.TaskType.DEADLINE, description, deadline);
} catch (NoSuchElementException e) {
// user imput after task type is blank
System.out.println("Oops! You did not enter a description or deadline!");
}
break;
default:
throw new InputMismatchException();
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
this.type = "T";
}
}