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

[Cao] iP #466

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a0828cb
Added features for Greet, Echo and Exit
Aug 20, 2020
2a955ed
Added features of Level-2, Add and List
Aug 20, 2020
2960cdb
Added done feature, but not achieved
Aug 20, 2020
e6f5a1b
Add package main.java
Aug 30, 2020
d619ffa
Adjusted the robot's responding style
Aug 30, 2020
7a01956
Added a Task class, but did not merge it with the main class Duke.java
Aug 30, 2020
23ff51e
added printDescription() method to Task class
Aug 30, 2020
aaf0db0
Merged Task.java class with Duke.java class, completed features for l…
Aug 30, 2020
b989315
Added classes Todo, Deadline, Event.
Aug 30, 2020
46c1cf5
Added feature for Automated Text UI Testing
Aug 30, 2020
bf02861
Added feature for Exception handling
Sep 2, 2020
9ed888d
Handled exceptions for deadline
Sep 3, 2020
4630050
updated exceptions handling for event
Sep 3, 2020
eccd4bd
Finished delete function
Sep 3, 2020
518a798
Handled exception for Done
Sep 3, 2020
3d92ca2
Updated exception handling for delete operation
Sep 3, 2020
488eaec
Saved the list of tasks in a txt. file. Every time will load the data…
Sep 7, 2020
74ae682
solved the bug when the command.txt does not exist.
Sep 7, 2020
fc5812c
Stored Deadline data as java.time.LocalDate
Sep 9, 2020
fd6a9b3
Merge branch 'branch-Level-7'
Sep 9, 2020
9528c06
Merge branch 'branch-Level-8'
Sep 9, 2020
b6efb63
Revise the OOP of the project
Ringo1225 Sep 9, 2020
ecd9609
Add Junit test cases
Ringo1225 Sep 9, 2020
7dbaa04
add jar file on github
Ringo1225 Sep 9, 2020
ad53f61
Adds java docs
Ringo1225 Sep 9, 2020
2a51b71
Tweak the code to comply with a coding standard
Ringo1225 Sep 9, 2020
18690fd
Add find feature
Ringo1225 Sep 9, 2020
48642d3
Merge branch 'branch-A-JavaDoc'
Ringo1225 Sep 9, 2020
500c754
Merge branch 'branch-A-CodingStandard'
Ringo1225 Sep 9, 2020
4e5da11
Merge branch 'branch-Level-9'
Ringo1225 Sep 9, 2020
04d380f
Use Gradle to automate some of the build tasks of the project.
Ringo1225 Sep 9, 2020
da7df49
Merge branch 'branch-A-Gradle'
Ringo1225 Sep 9, 2020
e9dc761
Revise the project structure
Ringo1225 Sep 9, 2020
d743259
Revise project structure
Ringo1225 Sep 13, 2020
e9542b0
Edit build.gradle
Ringo1225 Sep 13, 2020
88955d9
Add some GUI feature
Ringo1225 Sep 16, 2020
64d7ccd
Improve GUI
Ringo1225 Sep 16, 2020
a2fe141
Restructure Parser
Ringo1225 Sep 16, 2020
03db3d5
fix bug for some operation
Ringo1225 Sep 17, 2020
6177d62
Merge branch 'master' into branch-GUI
Ringo1225 Sep 17, 2020
6ed168a
Finish GUI feature
Ringo1225 Sep 17, 2020
6703d18
Restructure project
Ringo1225 Sep 17, 2020
4867fea
Add FXML
Ringo1225 Sep 17, 2020
600c0da
Merge branch 'branch-GUI'
Ringo1225 Sep 17, 2020
31edbef
Try to create a jar file
Ringo1225 Sep 17, 2020
c24a998
Add assertions
Ringo1225 Sep 18, 2020
7dd194a
Improve code quality
Ringo1225 Sep 18, 2020
a99084c
Add feature: FixedDurationTasks
Ringo1225 Sep 18, 2020
3f9875b
Merge pull request #3 from Ringo1225/branch-A-Assertions
Ringo1225 Sep 18, 2020
2b5a07c
Merge branch 'master' of https://github.com/Ringo1225/ip
Ringo1225 Sep 18, 2020
4e15055
Merge branch 'master' into branch-A-CodeQuality
Ringo1225 Sep 18, 2020
ce96300
Merge branch 'branch-A-CodeQuality' into branch-B-FixedDurationTasks
Ringo1225 Sep 18, 2020
19baa19
Merge pull request #1 from Ringo1225/branch-A-CodeQuality
Ringo1225 Sep 18, 2020
25b7998
Merge branch 'master' of https://github.com/Ringo1225/ip
Ringo1225 Sep 18, 2020
1e4cdf2
Merge branch 'master' into branch-B-FixedDurationTasks
Ringo1225 Sep 18, 2020
1046b5e
Merge pull request #2 from Ringo1225/branch-B-FixedDurationTasks
Ringo1225 Sep 18, 2020
19b36fb
Merge branch 'master' of https://github.com/Ringo1225/ip
Ringo1225 Sep 18, 2020
cf73057
Add reuse acknowlegement
Ringo1225 Sep 18, 2020
4037756
Add Ui.png
Ringo1225 Sep 18, 2020
1655726
Update user guide
Ringo1225 Sep 18, 2020
4b7aeb1
Set theme jekyll-theme-minimal
Ringo1225 Sep 18, 2020
74aa3da
Revise user guide
Ringo1225 Sep 18, 2020
cbb962b
Merge branch 'master' of https://github.com/Ringo1225/ip
Ringo1225 Sep 18, 2020
3457ff4
Revise User Guide
Ringo1225 Sep 18, 2020
8e00007
Revise User Guide
Ringo1225 Sep 18, 2020
9a57b7a
Set theme jekyll-theme-midnight
Ringo1225 Sep 18, 2020
5513e6d
revise build.gradle, generate a jar file
Ringo1225 Sep 18, 2020
bd54f7a
Merge branch 'master' of https://github.com/Ringo1225/ip
Ringo1225 Sep 18, 2020
777b9e0
update jar file version
Ringo1225 Sep 18, 2020
1615411
Set theme jekyll-theme-minimal
Ringo1225 Oct 10, 2020
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
213 changes: 213 additions & 0 deletions src/main/java/CommandHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package main.java;

import java.util.ArrayList;
import java.util.Scanner;

public class CommandHandler {
Scanner sc;
ArrayList<Task> taskList;

public CommandHandler() {
this.sc = new Scanner(System.in);
this.taskList = new ArrayList<>();
}

public void handleCommand() {
while (true) {
String command = sc.next();
switch (command) {
case "bye":

Choose a reason for hiding this comment

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

There's no indention for the case statements. It should be 'aligned' with the switch statement.

handleBye();
return;
case "list":
handleList();
break;
case "done":
try {
handleDone();
} catch (DukeException e) {
System.out.println(" ____________________________________________________________");

Choose a reason for hiding this comment

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

Maybe you could abstract out this border line as a variable, then call it whenever you need it. Makes the code tidy.

System.out.println(" " + e.getMessage());
System.out.println(" ____________________________________________________________\n");
}
break;
case "delete":
try {
handleDelete();
} catch (DukeException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" " + e.getMessage());
System.out.println(" ____________________________________________________________\n");
}
break;
case "todo":
try {
handleTodo();
} catch (DukeException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" " + e.getMessage());
System.out.println(" ____________________________________________________________\n");
}
break;
case "deadline":
try {
handleDeadline();
} catch (DukeException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" " + e.getMessage());
System.out.println(" ____________________________________________________________\n");
}
break;
case "event":
try {
handleEvent();
} catch (DukeException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" " + e.getMessage());
System.out.println(" ____________________________________________________________\n");
}
break;
default:
try {
handleDefault();
} catch (DukeException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" " + e.getMessage());
System.out.println(" ____________________________________________________________\n");
}
}
}
}

public void handleBye() {
System.out.println(" ____________________________________________________________");
System.out.println(" Bye. Hope to see you again soon!");
System.out.println(" ____________________________________________________________\n");
return;
}

public void handleList() {
System.out.println(" ____________________________________________________________");
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < taskList.size(); i++) {
System.out.print(" " + (i + 1) + ".");
taskList.get(i).printDescription();
}
System.out.println(" ____________________________________________________________\n");
}

public void handleDone() throws DukeException {
String doneCommand = sc.nextLine();
int index = 0;
if (doneCommand.isEmpty()) {
throw new DukeException("\u2639 OOPS!!! I need to know the index of the task to be done!");
}
try {
index = Integer.parseInt(doneCommand.stripLeading());
} catch (NumberFormatException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" \u2639 Please enter a valid integer!!");
System.out.println(" ____________________________________________________________\n");
return;
}
if (index > taskList.size()) {
throw new DukeException("\u2639 Your number is too large!!");
}
Task currentTask = taskList.get(index - 1);
currentTask.markAsDone();
System.out.println(" ____________________________________________________________");
System.out.println(" Nice! I've marked this task as done:");
System.out.print(" ");
currentTask.printDescription();
System.out.println(" ____________________________________________________________\n");
}

Choose a reason for hiding this comment

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

Perhaps you could add appropriate line breaks to enhance readability


public void handleDelete() throws DukeException {
String deleteCommand = sc.nextLine();
int index = 0;
if (deleteCommand.isEmpty()) {
throw new DukeException("\u2639 OOPS!!! I need to know the index of the task to be deleted!");
}
try {
index = Integer.parseInt(deleteCommand.stripLeading());
} catch (NumberFormatException e) {
System.out.println(" ____________________________________________________________");
System.out.println(" \u2639 Please enter a valid integer!!");
System.out.println(" ____________________________________________________________\n");
return;
}
if (index > taskList.size()) {
throw new DukeException("\u2639 Your number is too large!!");
}
Task currentTask = taskList.get(index - 1);
taskList.remove(index - 1);
System.out.println(" ____________________________________________________________");
System.out.println(" Noted! I've removed this task:");
System.out.print(" ");
currentTask.printDescription();
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(" ____________________________________________________________\n");
Copy link

@junhui-phoon junhui-phoon Sep 6, 2020

Choose a reason for hiding this comment

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

Same comment as above. Line breaks for readability.

}

public void handleTodo() throws DukeException {
String todoDescription = sc.nextLine();
if (todoDescription.isEmpty()) {
throw new DukeException("\u2639 OOPS!!! The description of a todo cannot be empty.");
}
Todo todo = new Todo(todoDescription);
taskList.add(todo);
System.out.println(" ____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.print(" ");
todo.printDescription();
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(" ____________________________________________________________\n");
}

public void handleDeadline() throws DukeException {

String deadlineCommand = sc.nextLine();
if (deadlineCommand.isEmpty()) {
throw new DukeException("\u2639 OOPS!!! The description of a deadline cannot be empty.");
}
if (!deadlineCommand.contains("/by")) {
throw new DukeException("\u2639 OOPS!!! The timing of a deadline cannot be empty.");
}
String[] strings = deadlineCommand.split("/by");
String deadlineDescription = strings[0];
String time = strings[1];
Deadline deadline = new Deadline(deadlineDescription, time);
taskList.add(deadline);
System.out.println(" ____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.print(" ");
deadline.printDescription();
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(" ____________________________________________________________\n");
}

public void handleEvent() throws DukeException{
String eventCommand = sc.nextLine();
if (eventCommand.isEmpty()) {
throw new DukeException("\u2639 OOPS!!! The description of an event cannot be empty.");
}
if (!eventCommand.contains("/at")) {
throw new DukeException("\u2639 OOPS!!! The timing of an event cannot be empty.");
}
String[] strings = eventCommand.split("/at");
String eventDescription = strings[0];
String date = strings[1];
Event event = new Event(eventDescription, date);
taskList.add(event);
System.out.println(" ____________________________________________________________");
System.out.println(" Got it. I've added this task:");
System.out.print(" ");
event.printDescription();
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(" ____________________________________________________________\n");
}

public void handleDefault() throws DukeException {
throw new DukeException("\u2639 OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
16 changes: 16 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main.java;

public class Deadline extends Task {
protected String deadline;

Choose a reason for hiding this comment

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

Suggest using private keyword instead of protected.


public Deadline(String description, String deadline) {
super(description);
this.deadline = deadline;
}

@Override
public void printDescription() {
System.out.println("[D][" + getStatusIcon()
+ "]" + description + "(by:" + deadline + ")");
}
}
13 changes: 11 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package main.java;

public class Duke {
public static void main(String[] args) {
public static void main(String[] args){
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| _ \\ _ _| | _____\n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println(" ____________________________________________________________");
System.out.println(" Hello! I'm Duke\n What can I do for you?");

Choose a reason for hiding this comment

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

different parts of the code can be grouped together as a method, make it easier for abstraction.

System.out.println(" ____________________________________________________________\n");

CommandHandler commandHandler = new CommandHandler();
commandHandler.handleCommand();
}
}

7 changes: 7 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main.java;

public class DukeException extends Exception {
public DukeException(String ErrorMessage) {
super(ErrorMessage);
}
}
16 changes: 16 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main.java;

public class Event extends Task {
protected String time;

Choose a reason for hiding this comment

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

same suggestion as deadline


public Event(String description, String time) {
super(description);
this.time = time;
}

@Override
public void printDescription() {
System.out.println("[E][" + getStatusIcon()
+ "]" + description + "(at:" + time + ")");
}
}
23 changes: 23 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main.java;

public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718");
}

public void markAsDone() {
this.isDone = true;
}

public void printDescription() {
System.out.println("[" + getStatusIcon() + "] " + description);
}
}
12 changes: 12 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main.java;

public class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public void printDescription() {
System.out.println("[T][" + getStatusIcon() + "]" + description);
}
}
Loading