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

[Eugene Ong Wei Xiang] iP #29

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
f6fd68b
Level-1 Done
Eugene-Ong-W-X Aug 14, 2022
7378eb9
Level-2 Done
Eugene-Ong-W-X Aug 16, 2022
a044c10
Level-3 Done
Eugene-Ong-W-X Aug 16, 2022
5fe495d
Level-4 Done
Eugene-Ong-W-X Aug 16, 2022
91f2fff
A-TextUiTesting Done
Eugene-Ong-W-X Aug 17, 2022
9658653
Level-5 Done
Eugene-Ong-W-X Aug 17, 2022
6f8dc32
Level-6 Done
Eugene-Ong-W-X Aug 17, 2022
30f5bb8
A-Enums Done
Eugene-Ong-W-X Aug 17, 2022
6d379a7
CheckStyle Done
Eugene-Ong-W-X Aug 17, 2022
2013e87
Add Level-7 | Read from & Write to File
Eugene-Ong-W-X Aug 20, 2022
84d0c49
Add Level-8 | Timestamps properly implemented
Eugene-Ong-W-X Aug 20, 2022
75f3d53
Merge branch 'branch-Level-7'
Eugene-Ong-W-X Aug 20, 2022
8209332
Merge branch 'branch-Level-8' into HEAD
Eugene-Ong-W-X Aug 20, 2022
b8119d6
More OOP | Add Ui, Parser, TaskList classes
Eugene-Ong-W-X Aug 20, 2022
7823c9c
Rename Duke/Alfred to Ren and Add 2 packages
Eugene-Ong-W-X Aug 20, 2022
422ded7
Merge branch 'add-gradle-support' of https://github.com/nus-cs2103-AY…
Eugene-Ong-W-X Aug 20, 2022
1f4739e
Add Gradle Support
Eugene-Ong-W-X Aug 20, 2022
f6491cf
Add JUnit Tests
Eugene-Ong-W-X Aug 20, 2022
6605c20
Release v0.2 (Packaging as JAR file)
Eugene-Ong-W-X Aug 20, 2022
2e039ea
Add JavaDoc
Eugene-Ong-W-X Aug 20, 2022
176828a
Java Standards: Fixed test codes
Eugene-Ong-W-X Aug 20, 2022
c7fc8d2
Add Find Feature
Eugene-Ong-W-X Aug 20, 2022
aa2133f
Merge branch 'branch-A-JavaDoc'
Eugene-Ong-W-X Aug 20, 2022
dc89a4b
Merge branch 'branch-A-CodingStandard'
Eugene-Ong-W-X Aug 20, 2022
1f496d9
Merge branch 'branch-Level-9'
Eugene-Ong-W-X Aug 20, 2022
443b11a
Use CheckStyle
Eugene-Ong-W-X Aug 25, 2022
7f9d8b9
Merge branch 'branch-A-CheckStyle'
Eugene-Ong-W-X Aug 25, 2022
3b647fc
Upgrade to GUI from Text UI
Eugene-Ong-W-X Aug 31, 2022
8562c90
Merge branch 'branch-Level-10'
Eugene-Ong-W-X Aug 31, 2022
730da76
Add and enable Assertions
Eugene-Ong-W-X Sep 3, 2022
5b3b597
Improve Code Quality
Eugene-Ong-W-X Sep 3, 2022
c925dde
Merge pull request #2 from Eugene-Ong-W-X/branch-A-CodeQuality
Eugene-Ong-W-X Sep 3, 2022
9122d13
Merge branch 'master' into branch-A-Assertions
Eugene-Ong-W-X Sep 3, 2022
64423eb
Merge pull request #1 from Eugene-Ong-W-X/branch-A-Assertions
Eugene-Ong-W-X Sep 3, 2022
1ee5cba
Set up Java CI using Github Actions
Eugene-Ong-W-X Sep 4, 2022
f2757f6
Fix for Java CI implementation
Eugene-Ong-W-X Sep 4, 2022
232a235
Fix 2 for Java CI implementation
Eugene-Ong-W-X Sep 4, 2022
1ec902d
Add Sort Feature
Eugene-Ong-W-X Sep 4, 2022
141d85e
Merge branch 'branch-BCD-Extension'
Eugene-Ong-W-X Sep 4, 2022
ebd82ba
Set up Ren Website
Eugene-Ong-W-X Sep 9, 2022
2683455
Update README.md
Eugene-Ong-W-X Sep 9, 2022
faad80a
Fix Code Quality
Eugene-Ong-W-X Sep 10, 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
9 changes: 9 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/**
Copy link

Choose a reason for hiding this comment

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

Sorry I just saw you had Checkstyle added so ignore all the previous mentions of spacing issues, they should be resolved by here. Regardless formatting wise I mean there aren't any styling violations apart from some small naming potential improvements! Really good job man :)

* Deadline Task represents an action that needs to be done by a certain date or time.
*/
public class Deadline extends Task {
protected String dateTime;

/**
* Constructor for a Deadline Task.
*
* @param description the description of the Task
* @param dateTime the deadline of the Task
*/
public Deadline(String description, String dateTime) {
super(description);
this.dateTime = dateTime;
Expand Down
221 changes: 114 additions & 107 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import java.util.ArrayList;
import java.util.Scanner;

/**
* Duke is a Task Manager program that helps a user keep track of and manager their tasks.
*/
public class Duke {
/**
* Takes in commands entered by the user.
Expand All @@ -18,17 +21,6 @@ public class Duke {
*/
private static int pointer = 0;

enum TaskType {
TODO,
DEADLINE,
EVENT
}

enum TaskFunc {
MARK,
UNMARK
}

private static void speak(String message) {
System.out.println("============================================================\n");
System.out.println(message);
Expand All @@ -46,31 +38,31 @@ private static void goodbye() {
private static void addTask(TaskType type, String task, String dateTime) {
Task newTask;
switch (type) {
case TODO:
newTask = new Todo(task);
break;
case DEADLINE:
newTask = new Deadline(task, dateTime);
break;
case EVENT:
newTask = new Event(task, dateTime);
break;
default:
newTask = new Task(task);
case TODO:
newTask = new Todo(task);
break;
case DEADLINE:
newTask = new Deadline(task, dateTime);
break;
case EVENT:
newTask = new Event(task, dateTime);
break;
default:
newTask = new Task(task);
}
tasks.add(newTask);
pointer++;
speak(" Understood. I have added the following task:\n" +
" " + newTask +
" You have a total of " + pointer + " task(s).\n");
speak(" Understood. I have added the following task:\n"
+ " " + newTask
+ " You have a total of " + pointer + " task(s).\n");
}

private static void deleteTask(int taskNum) throws DukeException {
if (taskNum <= pointer && taskNum > 0) {
pointer--;
speak(" Understood. I have removed the following task:\n" +
" " + tasks.get(taskNum - 1) +
" You have a total of " + pointer + " task(s).\n");
speak(" Understood. I have removed the following task:\n"
+ " " + tasks.get(taskNum - 1)
+ " You have a total of " + pointer + " task(s).\n");
tasks.remove(taskNum - 1);
} else {
throw new DukeException("Please indicate a task no. between 1 to " + pointer + ".");
Expand All @@ -80,12 +72,13 @@ private static void deleteTask(int taskNum) throws DukeException {
private static void updateTask(TaskFunc func, int taskNum) throws DukeException {
if (taskNum <= pointer && taskNum > 0) {
switch (func) {
case MARK:
speak(tasks.get(taskNum - 1).mark());
break;
case UNMARK:
speak(tasks.get(taskNum - 1).unmark());
break;
case MARK:
Copy link

Choose a reason for hiding this comment

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

Really good use of enums! Properly indented as well might just steal it heh

speak(tasks.get(taskNum - 1).mark());
break;
case UNMARK:
speak(tasks.get(taskNum - 1).unmark());
break;
default:
}
} else {
throw new DukeException("Please indicate a task no. between 1 to " + pointer + ".");
Expand Down Expand Up @@ -116,90 +109,93 @@ private static void parseCommand(String cmd) throws DukeException {
boolean hasSecondTerm = firstParse.length > 1;

switch (firstTerm) {
case "bye":
goodbye();
case "bye":
goodbye();
break;
case "todo":
if (hasSecondTerm) {
addTask(TaskType.TODO, firstParse[1], "");
break;
case "todo":
if (hasSecondTerm) {
addTask(TaskType.TODO, firstParse[1], "");
} else {
throw new DukeException("Please provide a description for the todo.");
}
case "deadline":
if (hasSecondTerm) {
String[] secondParse = firstParse[1].split("/by", 2);
if (secondParse.length > 1) {
addTask(TaskType.DEADLINE, secondParse[0], secondParse[1]);
break;
} else {
throw new DukeException("Please provide a description for the todo.");
}
case "deadline":
if (hasSecondTerm) {
String[] secondParse = firstParse[1].split("/by", 2);
if (secondParse.length > 1) {
addTask(TaskType.DEADLINE, secondParse[0], secondParse[1]);
break;
} else {
throw new DukeException("Please provide a date/time for the deadline.");
}
} else {
throw new DukeException("Please provide a description for the deadline.");
throw new DukeException("Please provide a date/time for the deadline.");
}
case "event":
if (hasSecondTerm) {
String[] secondParse = firstParse[1].split("/at", 2);
if (secondParse.length > 1) {
addTask(TaskType.EVENT, secondParse[0], secondParse[1]);
break;
} else {
throw new DukeException("Please provide a date/time for the event.");
}
} else {
throw new DukeException("Please provide a description for the event.");
}
case "delete":
try {
String secondTerm = hasSecondTerm
? firstParse[1].split(" ", 2)[0]
: "0";
deleteTask(Integer.parseInt(secondTerm));
break;
} catch (NumberFormatException e) {
throw new DukeException("Please indicate the task no. in digits.");
} catch (DukeException f) {
speak(f.toString());
break;
}
case "mark":
try {
String secondTerm = hasSecondTerm
? firstParse[1].split(" ", 2)[0]
: "0";
updateTask(TaskFunc.MARK, Integer.parseInt(secondTerm));
break;
} catch (NumberFormatException e) {
throw new DukeException("Please indicate the task no. in digits.");
} catch (DukeException f) {
speak(f.toString());
break;
}
case "unmark":
try {
String secondTerm = hasSecondTerm
? firstParse[1].split(" ", 2)[0]
: "0";
updateTask(TaskFunc.UNMARK, Integer.parseInt(secondTerm));
break;
} catch (NumberFormatException e) {
throw new DukeException("Please indicate the task no. in digits.");
} catch (DukeException f) {
speak(f.toString());
} else {
throw new DukeException("Please provide a description for the deadline.");
}
case "event":
if (hasSecondTerm) {
String[] secondParse = firstParse[1].split("/at", 2);
if (secondParse.length > 1) {
addTask(TaskType.EVENT, secondParse[0], secondParse[1]);
break;
} else {
throw new DukeException("Please provide a date/time for the event.");
}
case "list":
listTasks();
} else {
throw new DukeException("Please provide a description for the event.");
}
case "delete":
try {
String secondTerm = hasSecondTerm
? firstParse[1].split(" ", 2)[0]
: "0";
deleteTask(Integer.parseInt(secondTerm));
break;
case "empty":
emptyList();
} catch (NumberFormatException e) {
throw new DukeException("Please indicate the task no. in digits.");
} catch (DukeException f) {
speak(f.toString());
break;
default:
throw new DukeException("Please enter a supported command.");
}
case "mark":
try {
String secondTerm = hasSecondTerm
? firstParse[1].split(" ", 2)[0]
: "0";
updateTask(TaskFunc.MARK, Integer.parseInt(secondTerm));
break;
} catch (NumberFormatException e) {
throw new DukeException("Please indicate the task no. in digits.");
} catch (DukeException f) {
speak(f.toString());
break;
}
case "unmark":
try {
String secondTerm = hasSecondTerm
? firstParse[1].split(" ", 2)[0]
: "0";
updateTask(TaskFunc.UNMARK, Integer.parseInt(secondTerm));
break;
} catch (NumberFormatException e) {
throw new DukeException("Please indicate the task no. in digits.");
} catch (DukeException f) {
speak(f.toString());
break;
}
case "list":
listTasks();
break;
case "empty":
emptyList();
break;
default:
throw new DukeException("Please enter a supported command.");
}
}

/**
* Runs the Duke program until the user exits with the 'bye' command.
*/
public static void main(String[] args) {
greet();

Expand All @@ -214,4 +210,15 @@ public static void main(String[] args) {
}
}
}

enum TaskType {
TODO,
DEADLINE,
EVENT
}

enum TaskFunc {
MARK,
UNMARK
}
}
5 changes: 4 additions & 1 deletion src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* DukeExceptions represent errors in user input when using Alfred.
*/
public class DukeException extends Exception {
public DukeException(String message) {
super(message);
}

@Override
public String toString() {
return " ☹ Apologies! "+ super.getMessage() + "\n";
return " ☹ Apologies! " + super.getMessage() + "\n";
}
}
9 changes: 9 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/**
* Event Task represents an event that takes place between certain dates/time.
*/
public class Event extends Task {
protected String dateTime;

/**
* Constructor for an Event Task.
*
* @param description the description of the Event
* @param dateTime the start and end dates/time of the Event
*/
public Event(String description, String dateTime) {
super(description);
this.dateTime = dateTime;
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
/**
* Parent Class for all Tasks.
*/
public class Task {
protected String description;
protected boolean isDone;

/**
* Constructor for a Task.
*
* @param description the description of the Task
*/
public Task(String description) {
this.description = description;
this.isDone = false;
}

/**
* Sets the Task as completed.
*
* @return string containing the completed message, to be displayed to the user
*/
public String mark() {
this.isDone = true;
return " Great job! I will mark the task as completed.\n" +
" " + this;
return " Great job! I will mark the task as completed.\n"
+ " " + this;
}

/**
* Sets the Task as uncompleted.
*
* @return string containing the uncompleted message, to be displayed to the user
*/
public String unmark() {
this.isDone = false;
return " Understood. I will mark the task as uncompleted.\n" +
" " + this;
return " Understood. I will mark the task as uncompleted.\n"
+ " " + this;
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Todo Task represents an action that needs to be done.
*/
public class Todo extends Task {
public Todo(String description) {
super(description);
Expand Down