-
Notifications
You must be signed in to change notification settings - Fork 461
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
Eugene-Ong-W-X
wants to merge
43
commits into
nus-cs2103-AY2223S1:master
Choose a base branch
from
Eugene-Ong-W-X:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
556af3f
Add Gradle support
f6fd68b
Level-1 Done
Eugene-Ong-W-X 7378eb9
Level-2 Done
Eugene-Ong-W-X a044c10
Level-3 Done
Eugene-Ong-W-X 5fe495d
Level-4 Done
Eugene-Ong-W-X 91f2fff
A-TextUiTesting Done
Eugene-Ong-W-X 9658653
Level-5 Done
Eugene-Ong-W-X 6f8dc32
Level-6 Done
Eugene-Ong-W-X 30f5bb8
A-Enums Done
Eugene-Ong-W-X 6d379a7
CheckStyle Done
Eugene-Ong-W-X 2013e87
Add Level-7 | Read from & Write to File
Eugene-Ong-W-X 84d0c49
Add Level-8 | Timestamps properly implemented
Eugene-Ong-W-X 75f3d53
Merge branch 'branch-Level-7'
Eugene-Ong-W-X 8209332
Merge branch 'branch-Level-8' into HEAD
Eugene-Ong-W-X b8119d6
More OOP | Add Ui, Parser, TaskList classes
Eugene-Ong-W-X 7823c9c
Rename Duke/Alfred to Ren and Add 2 packages
Eugene-Ong-W-X 422ded7
Merge branch 'add-gradle-support' of https://github.com/nus-cs2103-AY…
Eugene-Ong-W-X 1f4739e
Add Gradle Support
Eugene-Ong-W-X f6491cf
Add JUnit Tests
Eugene-Ong-W-X 6605c20
Release v0.2 (Packaging as JAR file)
Eugene-Ong-W-X 2e039ea
Add JavaDoc
Eugene-Ong-W-X 176828a
Java Standards: Fixed test codes
Eugene-Ong-W-X c7fc8d2
Add Find Feature
Eugene-Ong-W-X aa2133f
Merge branch 'branch-A-JavaDoc'
Eugene-Ong-W-X dc89a4b
Merge branch 'branch-A-CodingStandard'
Eugene-Ong-W-X 1f496d9
Merge branch 'branch-Level-9'
Eugene-Ong-W-X 443b11a
Use CheckStyle
Eugene-Ong-W-X 7f9d8b9
Merge branch 'branch-A-CheckStyle'
Eugene-Ong-W-X 3b647fc
Upgrade to GUI from Text UI
Eugene-Ong-W-X 8562c90
Merge branch 'branch-Level-10'
Eugene-Ong-W-X 730da76
Add and enable Assertions
Eugene-Ong-W-X 5b3b597
Improve Code Quality
Eugene-Ong-W-X c925dde
Merge pull request #2 from Eugene-Ong-W-X/branch-A-CodeQuality
Eugene-Ong-W-X 9122d13
Merge branch 'master' into branch-A-Assertions
Eugene-Ong-W-X 64423eb
Merge pull request #1 from Eugene-Ong-W-X/branch-A-Assertions
Eugene-Ong-W-X 1ee5cba
Set up Java CI using Github Actions
Eugene-Ong-W-X f2757f6
Fix for Java CI implementation
Eugene-Ong-W-X 232a235
Fix 2 for Java CI implementation
Eugene-Ong-W-X 1ec902d
Add Sort Feature
Eugene-Ong-W-X 141d85e
Merge branch 'branch-BCD-Extension'
Eugene-Ong-W-X ebd82ba
Set up Ren Website
Eugene-Ong-W-X 2683455
Update README.md
Eugene-Ong-W-X faad80a
Fix Code Quality
Eugene-Ong-W-X File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
@@ -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); | ||
|
@@ -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 + "."); | ||
|
@@ -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: | ||
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. 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 + "."); | ||
|
@@ -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(); | ||
|
||
|
@@ -214,4 +210,15 @@ public static void main(String[] args) { | |
} | ||
} | ||
} | ||
|
||
enum TaskType { | ||
TODO, | ||
DEADLINE, | ||
EVENT | ||
} | ||
|
||
enum TaskFunc { | ||
MARK, | ||
UNMARK | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 :)