Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
c79efa6
.gitignore: included .class files to be omitted from being committed
Sampy147 Aug 18, 2022
327c569
Duke.java: Level-1 completed
Sampy147 Aug 18, 2022
a4346b2
Duke.java: Level-2 completed
Sampy147 Aug 18, 2022
df16435
Duke.java: Level-1 v1.1 improved
Sampy147 Aug 19, 2022
fd542b8
Duke.java: Level-2 v1.1 improved
Sampy147 Aug 19, 2022
5d410b8
Duke.java: Level-2 v1.2 improved
Sampy147 Aug 19, 2022
53a12ae
Duke.java, Task.java, Tasklist.java: Updated with level 3 requirements
Sampy147 Aug 21, 2022
a003efa
Duke.java,Tasklist.java modified. Deadline.java, Event.java, ToDo.jav…
Sampy147 Aug 21, 2022
738c9a8
Automation testing done
Sampy147 Aug 22, 2022
17bb08c
Level-5 handle errors done
Sampy147 Aug 22, 2022
9512919
Level-6 done
Sampy147 Aug 22, 2022
83446a2
Level-7 completed
Sampy147 Sep 3, 2022
d777be2
level-7 completed
Sampy147 Sep 3, 2022
1a2c997
Level-7 completed
Sampy147 Sep 3, 2022
0b16da0
Level-7 completed
Sampy147 Sep 3, 2022
32500d1
Level-8 completed
Sampy147 Sep 6, 2022
70bb7e5
Level-8 completed
Sampy147 Sep 6, 2022
12680d8
Merge branch 'branch-Level-7'
Sampy147 Sep 6, 2022
5130f46
Merge branch 'branch-Level-8 successfully
Sampy147 Sep 6, 2022
f110900
More-OOP done with prev commit code as comments
Sampy147 Sep 8, 2022
507e8b8
A-MoreOOP completed
Sampy147 Sep 8, 2022
d99e1ff
Divided class into packages
Sampy147 Sep 8, 2022
1fdadeb
Merge remote-tracking branch 'upstream/add-gradle-support'
Sampy147 Sep 8, 2022
27252f0
Build automation with Gradle added
Sampy147 Sep 8, 2022
371855c
Build automation with Gradle added
Sampy147 Sep 8, 2022
6027556
added JUnit tests to the project
Sampy147 Sep 9, 2022
dd53432
Merge branch 'master' of https://github.com/Sampy147/ip
Sampy147 Sep 9, 2022
0524628
Add JUnit to current project
Sampy147 Sep 9, 2022
ef6a4b7
Attach project as JAR file in new release
Sampy147 Sep 11, 2022
7a9cd02
Add javadocs
Sampy147 Sep 11, 2022
91ff3bb
Remove unnecessary files duke.txt and data/duke.txt
Sampy147 Sep 11, 2022
9f1df79
Modify files to comply to Java's Coding Standard
Sampy147 Sep 11, 2022
52505dc
Add Level-9 find feature
Sampy147 Sep 12, 2022
56949df
Merge branch 'branch-A-JavaDoc'
Sampy147 Sep 12, 2022
ab7eb48
Merge branch-A-CodingStandard with master
Sampy147 Sep 12, 2022
ecbc9fd
Merge branch-Level-9 with master
Sampy147 Sep 12, 2022
ed9edd3
Configure javaFx
Sampy147 Sep 14, 2022
cc0eb58
Add GUI functionality to duke
Sampy147 Sep 15, 2022
1bf6279
Merge branch 'branch-Level-10'
Sampy147 Sep 15, 2022
3b79a44
Add assertion statements
Sampy147 Sep 16, 2022
0517320
Improve code quality of existing code base
Sampy147 Sep 16, 2022
07e59f3
Merge pull request #2 from Sampy147/branch-A-Assertions
Sampy147 Sep 18, 2022
18a86c2
Merge branch 'branch-A-CodeQuality'
Sampy147 Sep 18, 2022
ada09a8
Merge master and branch-A-Assertions and resolve merge conflicts
Sampy147 Sep 18, 2022
0854fc2
Resolve merge conflicts
Sampy147 Sep 18, 2022
dd4a604
Merge branch 'master' of https://github.com/Sampy147/ip
Sampy147 Sep 19, 2022
4bd20cd
Implement extension C-Help
Sampy147 Sep 19, 2022
69abf4d
Message Class: Change invalid user input message
Sampy147 Sep 19, 2022
8b10487
Add User Guide for Duke
Sampy147 Sep 19, 2022
8feb9d5
Add comments to give credit for reused work
Sampy147 Sep 19, 2022
f7a0309
Amend README.md and improved formatting
Sampy147 Sep 19, 2022
60ac1a3
Amend README.md to improve formatting further
Sampy147 Sep 19, 2022
63089dd
Amend README to include proper line spacing
Sampy147 Sep 19, 2022
d86b26c
Amend line spacing in README.md further
Sampy147 Sep 19, 2022
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
/out/
/*.iml

# .class files
/.class/

# Gradle build files
/.gradle/
/build/
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String by;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This variable is only used within the class so it could use the private access modifier instead


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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + this.by + ")";
}
}
179 changes: 173 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,177 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {
private static final String horizontalBorder = "_________________________________\n";
private static final String INVALID_TODO_INPUT = " ☹ OOPS!!! The description of a todo cannot be empty.\n";
private static final String INVALID_DEADLINE_INPUT = "☹ OOPS!!! Please use proper deadline formatting: deadline {task} /by {time}\n";
private static final String INVALID_EVENT_INPUT = "☹ OOPS!!! Please use proper event formatting: event {task} /at {time}\n";
private static final String INVALID_ACCESS_EMPTY_TASKLIST = "☹ OOPS!!! Task does not exist. Initialise a task first, then try again\n";
private static final String INVALID_USER_INPUT = "☹ OOPS!!! Please use one of these keywords: {deadline, event, todo} followed by \\\"by\\\" and \\\"at\\\" for deadline and event tasks respectively.\n";

private Tasklist tasklist;

private Duke(){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It does not appear that this constructor is invoked so you could look into omitting this constructor.

this.tasklist = new Tasklist();
}

private Duke(Tasklist tasklist){
this.tasklist = tasklist;
}

private static String welcomeMessage(){
return horizontalBorder + "Hello! I'm Duke\nWhat can I do for you?\n" + horizontalBorder;
}

private static String byeMessage(){
return horizontalBorder + "Bye. Hope to see you again soon!\n" + horizontalBorder;
}

private String listContents(){
return horizontalBorder + this.tasklist + horizontalBorder;
}

public String addTaskMessage(String taskString) {
return horizontalBorder + "Got it. I've added this task:\n" + taskString + "\n" + "Now you have " + this.tasklist.getCount() + " tasks in the list.\n" + horizontalBorder;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line length for this line is pretty long so you could look into using line wrapping such as splitting at the addition operators.

}

public String taskNotFoundMessage(){
return "☹ OOPS!!! Task does not exist. Try another number between 1 and " + this.tasklist.getCount() + "\n";
}

private String markDoneMessage(int position) throws DukeException{
boolean isTaskMarked = this.tasklist.markTaskAtPos(position);
if (isTaskMarked) {
Task currentTask = this.tasklist.getTask(position);
return horizontalBorder + "Nice! I've marked this task as done:\n" + currentTask + "\n" + horizontalBorder;
} else if (this.tasklist.getCount() == 0) {
throw new DukeException(INVALID_ACCESS_EMPTY_TASKLIST);
} else {
throw new DukeException(taskNotFoundMessage());
}
}

private String unmarkDoneMessage(int position) throws DukeException {
boolean isTaskUnmarked = this.tasklist.unmarkTaskAtPos(position);
if (isTaskUnmarked) {
Task currentTask = this.tasklist.getTask(position);
return horizontalBorder + "OK, I've marked this task as not done yet:\n" + currentTask + "\n" + horizontalBorder;
} else if (this.tasklist.getCount() == 0) {
throw new DukeException(INVALID_ACCESS_EMPTY_TASKLIST);
} else {
throw new DukeException(taskNotFoundMessage());
}
}

private String deleteTaskMessage(int position) throws DukeException {
try {
Task deletedTask = this.tasklist.deleteTaskAtPos(position);
return horizontalBorder + "Noted. I've removed this task:\n" + deletedTask + "\n" + "" + "Now you have " + this.tasklist.getCount() + " tasks in the list.\n" + horizontalBorder;
} catch (IndexOutOfBoundsException e){
if (this.tasklist.getCount() == 0){
throw new DukeException(INVALID_ACCESS_EMPTY_TASKLIST);
} else {
throw new DukeException(taskNotFoundMessage());
}
}
}

private boolean isInteger(String value) {
try {
Integer.parseInt(value);
return true;
} catch (NumberFormatException e) {
return false;
}
}

private String makeToDoFromInput(String input) throws DukeException {
String description = input.substring("todo".length()).strip();
if (!description.equals("")) {
ToDo newToDo = new ToDo(description);
this.tasklist.add(newToDo);
return addTaskMessage(newToDo.toString());
} else {
throw new DukeException(INVALID_TODO_INPUT);
}
}

private String makeDeadlineFromInput(String input) throws DukeException {
String[] stringArray = input.substring("deadline".length()).strip().split("/by");
if (stringArray.length > 1) {
Deadline newDeadline = new Deadline(stringArray[0].strip(), stringArray[1].strip());
this.tasklist.add(newDeadline);
return addTaskMessage(newDeadline.toString());
} else {
throw new DukeException(INVALID_DEADLINE_INPUT);
}
}

private String makeEventFromInput(String input) throws DukeException{
String[] stringArray = input.substring("event".length()).strip().split("/at");
if (stringArray.length > 1) {
Event newEvent = new Event(stringArray[0].strip(), stringArray[1].strip());
this.tasklist.add(newEvent);
return addTaskMessage(newEvent.toString());
} else {
throw new DukeException(INVALID_EVENT_INPUT);
}
}

public void run(){
System.out.println(welcomeMessage());
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
boolean exitNow = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could consider using a variable name which sounds more like a Boolean such as isExit.

while(!exitNow) {
try {
String[] commandList = s.strip().split(" ");
String command = commandList[0].toLowerCase();
if (command.equals("bye") && commandList.length == 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can consider using switch statements here.

exitNow = true;
System.out.println(byeMessage());
} else if (command.equals("list") && commandList.length == 1) {
System.out.println(listContents());
} else if (command.equals("mark") && commandList.length > 1 && isInteger(commandList[1])) {
int taskIndexNum = Integer.parseInt(commandList[1]);
System.out.println(markDoneMessage(taskIndexNum));
} else if (command.equals("unmark") && commandList.length > 1 && isInteger(commandList[1])) {
int taskIndexNum = Integer.parseInt(commandList[1]);
System.out.println(unmarkDoneMessage(taskIndexNum));
} else if (command.equals("deadline")) {
System.out.println(makeDeadlineFromInput(s));
} else if (command.equals("event")) {
System.out.println(makeEventFromInput(s));
} else if (command.equals("todo")) {
System.out.println(makeToDoFromInput(s));
} else if (command.equals("delete") && commandList.length > 1 && isInteger(commandList[1])){
int taskIndexNum = Integer.parseInt(commandList[1]);
System.out.println(deleteTaskMessage(taskIndexNum));
} else if (!s.strip().equals("")) {
System.out.println(horizontalBorder + INVALID_USER_INPUT + horizontalBorder);
}
} catch (DukeException e) {
System.out.println(horizontalBorder + e.getMessage() + horizontalBorder);
} finally {
if (!exitNow) {
s = scan.nextLine();
}
}
}
scan.close();
}


public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Duke sampleDuke = new Duke(new Tasklist());
sampleDuke.run();
// ArrayList<String> a = new ArrayList<>();
// a.add("lol");
// a.add("gan");
// a.add("lasso");
// a.remove(1);
// for (int i = 0; i < a.size(); i++){
// System.out.println(a.get(i));
// }
}
}
5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class DukeException extends Exception{
public DukeException(String message){
super(message);
}
}
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{

protected String at;

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

@Override
public String toString(){
return "[E]" + super.toString() + " (at: " + this.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 {
protected String description;
protected boolean isDone;

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

public String getStatusIcon() {
return (this.isDone ? "X" : " ");
}

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

public void unmark() {
this.isDone = false;
}

@Override
public String toString(){
return "[" + getStatusIcon() + "] " + this.description;
}
}
59 changes: 59 additions & 0 deletions src/main/java/Tasklist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import java.util.ArrayList;

public class Tasklist {
private ArrayList<Task> taskArray;
private int count = 0;

public Tasklist(){
this.taskArray = new ArrayList<>();
}

public void add(Task task){
this.taskArray.add(task);
this.count += 1;
}

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

public int getCount(){
return this.count;
}

public boolean markTaskAtPos(int position){
try {
Task currTask = getTask(position);
currTask.markAsDone();
return true;
} catch (IndexOutOfBoundsException e) {
return false;
}
}

public boolean unmarkTaskAtPos(int position){
try {
Task currTask = getTask(position);
currTask.unmark();
return true;
} catch (IndexOutOfBoundsException e) {
return false;
}
}

public Task deleteTaskAtPos(int position) throws IndexOutOfBoundsException {
Task deletedTask = getTask(position);
this.taskArray.remove(position - 1);
this.count -= 1;
return deletedTask;
}

@Override
public String toString(){
String stringedList = "";
for (int i = 0; i < this.count; i++) {
stringedList += (i + 1) + ". " + getTask(i + 1).toString() + "\n";
}
return "Here are the tasks in your list:\n" + stringedList;
}
}
11 changes: 11 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class ToDo extends Task{

public ToDo(String description){
super(description);
}

@Override
public String toString(){
return "[T]" + super.toString();
}
}
56 changes: 50 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
_________________________________
Hello! I'm Duke
What can I do for you?
_________________________________

_________________________________
Got it. I've added this task:
[E][ ] Tuition (at: Mon 2-3pm )
Now you have 1 tasks in the list.
_________________________________

_________________________________
Got it. I've added this task:
[T][ ] Eat dinner
Now you have 2 tasks in the list.
_________________________________

_________________________________
Got it. I've added this task:
[D][ ] Math assignment submission (by: Friday)
Now you have 3 tasks in the list.
_________________________________

_________________________________
☹ OOPS!!! Please use one of these keywords: {deadline, event, todo} followed by \"by\" and \"at\" for deadline and event tasks respectively.
_________________________________

_________________________________
Nice! I've marked this task as done:
[T][X] Eat dinner
_________________________________

_________________________________
☹ OOPS!!! Task does not exist. Try another number between 1 and 3
_________________________________

_________________________________
Here are the tasks in your list:
1. [E][ ] Tuition (at: Mon 2-3pm )
2. [T][X] Eat dinner
3. [D][ ] Math assignment submission (by: Friday)
_________________________________

_________________________________
☹ OOPS!!! Please use proper deadline formatting: deadline {task} /by {time}
_________________________________

_________________________________
Bye. Hope to see you again soon!
_________________________________

9 changes: 9 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
event Tuition /at Mon 2-3pm
todo Eat dinner
deadline Math assignment submission /by Friday
make up bed
mark 2
unmark 0
list
deadline Math assignment 2
bye