-
Notifications
You must be signed in to change notification settings - Fork 269
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
[Sim Jia Ming] iP #316
Open
SimJM
wants to merge
57
commits into
nus-cs2103-AY2122S2:master
Choose a base branch
from
SimJM: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
[Sim Jia Ming] iP #316
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
d839859
Add Gradle support
6b8c2f2
Level1. Greet,Echo,Exit
SimJM 778d1e0
add Action class
SimJM 8009280
Level-2: added readBook(), returnBook()
SimJM 8fa8a55
Level-3: Mark as Done. Added Task class
SimJM 3357573
Level-4: todo, deadline, event
SimJM f2fabf0
A-TextUiTesting
SimJM a210a0f
Level-5 Handle Errors
SimJM 8a7ee50
Level-6 delete
SimJM a51d3f3
A-Enums
SimJM 5b8561d
refactor code (add TaskBank, Parser, User class)
SimJM 3d7329e
Level-7 Save
SimJM 5dcf7b0
minor edits
SimJM 6b65fea
incomplete branch
SimJM 4ab3dac
Add LocalDate and format date
SimJM 832f67b
implement date format
SimJM 507c6a3
Revert "implement date format"
SimJM 7f7f081
Revert "Revert "implement date format""
SimJM b8d7f64
Level 8 - add date format
SimJM 70d14c8
A-MoreOOP - Ui class
SimJM 8695409
A-Packages: organize classes into duke package
SimJM 4ac330a
Add JUnit tests
SimJM 26bba93
Package the App as a JAR file
SimJM 95823e5
A-JavaDoc - Add JavaDoc comments
SimJM 81232fa
A-CodingStandard - Tweak the code to comply with a coding standard
SimJM 726b27f
Merge branch 'branch-Level-8' into branch-A-CodingStandard
SimJM 52b6b7c
Level-9 Find - give users a way to find a task by searching for a key…
SimJM dee52c7
Merge branch 'branch-A-CodingStandard'
SimJM e1ccf9d
Merge branch 'branch-Level-9'
SimJM 3c83a87
Merge commit 'd8398594b7bc43da5eb865321c5a50cec4b3923d'
SimJM a018811
A-CheckStyle - edit coding style violations
SimJM fe06e8f
Level-10 GUI - add a GUI to Duke. Use the JavaFX technology to implem…
SimJM b3a9390
A-Varargs - not applicable
SimJM 53330a6
Add assertion
SimJM 8cfee6f
Improve code quality
SimJM 4aaed72
Merge branch 'branch-A-CodeQuality'
SimJM 25c776d
C-update - easily edit description of the Task
SimJM 807bab5
Improve the GUI
SimJM ba460f1
Improve GUI
SimJM ae805b1
Edit on code quality
SimJM 70a7cf8
Add update into help function
SimJM b5a30d2
Merge branch 'master' into branch-C-update
SimJM 6992122
Merge pull request #2 from SimJM/branch-C-update
SimJM 9e89a02
tidy up code
SimJM f56ff47
Set theme jekyll-theme-merlot
SimJM 9181b89
upload Ui.png
SimJM a914019
Merge branch 'master' of https://github.com/SimJM/ip
SimJM 046d881
Update README.md
SimJM 000f5a1
Update README.md
SimJM 8ed816b
Add exception handling in parser
SimJM b7ec4fe
Add exception handling
SimJM 09593f8
Add output
SimJM 98566a3
Update README
SimJM d232468
Update README.md
SimJM 4352935
Update README.md
SimJM f3191a8
Update README.md
SimJM 3bc0613
Update README.md
SimJM 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
refactor code (add TaskBank, Parser, User class)
commit 5b8561de7f6f6f0045eb47a9f7b93577c5ce099f
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,20 +1,18 @@ | ||
public class Deadline extends Task { | ||
protected final String sym = "D"; | ||
protected String day; | ||
private final String sym = "D"; | ||
private String day; | ||
|
||
Deadline (String description, String day) { | ||
super(description); | ||
this.day = day; | ||
} | ||
|
||
@Override | ||
String getSym() { | ||
return this.sym; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[%s][%s]%s (by:%s)", sym, super.getStatusIcon(), super.description, this.day); | ||
return String.format("[%s][%s]%s (by:%s)", sym, super.getStatusIcon(), super.getDescription(), this.day); | ||
} | ||
|
||
} |
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,107 +1,7 @@ | ||
// enums not applicable | ||
|
||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
ArrayList<Task> arrlst = new ArrayList<>(); | ||
String DASH = "____________________________________________________________"; | ||
Action act = new Action(); | ||
|
||
act.greet(); | ||
|
||
while (sc.hasNext()) { | ||
String phrase = sc.nextLine(); | ||
System.out.println(DASH); | ||
|
||
if (phrase.equals("list")) { | ||
act.showList(arrlst); | ||
} else if (phrase.equals("bye")) { | ||
act.bye(); | ||
System.out.println(DASH); | ||
break; | ||
} else { | ||
String[] arrWords = phrase.split(" "); | ||
try { // mark or unmark | ||
int num = Integer.valueOf(arrWords[1]); | ||
if (arrWords[0].equals("mark")) { | ||
arrlst.get(num - 1).markAsDone(); | ||
} else if (arrWords[0].equals("unmark")) { | ||
arrlst.get(num - 1).markAsNotDone(); | ||
} else if (arrWords[0].equals("delete")) { | ||
System.out.println("Noted. I've removed this task:"); | ||
Task t = arrlst.get(num - 1); | ||
String output = String.format("[%s][%s]%s", t.getSym(), t.getStatusIcon(), t.description); | ||
System.out.println(output); | ||
System.out.println("Now you have 4 tasks in the list."); | ||
arrlst.remove(num - 1); | ||
} else { | ||
System.out.println("siao eh"); | ||
} | ||
} catch (NumberFormatException nfe) { // add new task like read book, return book | ||
String gotIt = "Got it. I've added this task:"; | ||
|
||
if (arrWords[0].equals("todo")) { | ||
String remainingWords = ""; | ||
for (int i = 1; i < arrWords.length; i++) { | ||
remainingWords = remainingWords + " " + arrWords[i]; | ||
} | ||
Todo t = new Todo(remainingWords); | ||
arrlst.add(new Task(t.description, t.sym)); | ||
System.out.println(gotIt); | ||
System.out.println(t); | ||
String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size()); | ||
System.out.println(noOfTask); | ||
} else if (arrWords[0].equals("deadline")) { | ||
String remainingWords = ""; | ||
String dLine = ""; | ||
for (int i = 1; i < arrWords.length; i++) { | ||
if (arrWords[i].equals("/by")) { | ||
for (int j = i + 1; j < arrWords.length; j++) { | ||
dLine = dLine + " " + arrWords[j]; | ||
} | ||
break; | ||
} else { | ||
remainingWords = remainingWords + " " + arrWords[i]; | ||
} | ||
} | ||
Deadline t = new Deadline(remainingWords, dLine); | ||
arrlst.add(new Task(t.description, t.sym)); | ||
System.out.println(gotIt); | ||
System.out.println(t); | ||
String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size()); | ||
System.out.println(noOfTask); | ||
} else if (arrWords[0].equals("event")) { | ||
String remainingWords = ""; | ||
String dayAndTime = ""; | ||
for (int i = 1; i < arrWords.length; i++) { | ||
if (arrWords[i].equals("/at")) { | ||
for (int j = i + 1; j < arrWords.length; j++) { | ||
dayAndTime = dayAndTime + " " + arrWords[j]; | ||
} | ||
break; | ||
} else { | ||
remainingWords = remainingWords + " " + arrWords[i]; | ||
} | ||
} | ||
Event t = new Event(remainingWords, dayAndTime); | ||
arrlst.add(new Task(t.description, t.sym)); | ||
System.out.println(gotIt); | ||
System.out.println(t); | ||
String noOfTask = String.format("Now you have %d tasks in the list.", arrlst.size()); | ||
System.out.println(noOfTask); | ||
} | ||
} catch (ArrayIndexOutOfBoundsException aioobe) { // echo | ||
if (arrWords[0].equals("todo")) { | ||
System.out.println("OOPS!!! The description of a todo cannot be empty."); | ||
} else { | ||
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
} | ||
} | ||
} | ||
System.out.println(DASH); | ||
} | ||
User.start(); | ||
} | ||
} |
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,21 +1,18 @@ | ||
public class Event extends Task { | ||
protected final String sym = "E"; | ||
private final String sym = "E"; | ||
private String dayAndTime; | ||
|
||
Event (String description, String dayAndTime) { | ||
super(description); | ||
this.dayAndTime = dayAndTime; | ||
} | ||
|
||
@Override | ||
String getSym() { | ||
return this.sym; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[%s][%s]%s (at:%s)", sym, super.getStatusIcon(), super.description, this.dayAndTime); | ||
return String.format("[%s][%s] %s (at:%s)", sym, super.getStatusIcon(), super.getDescription(), this.dayAndTime); | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import java.util.ArrayList; | ||
|
||
public class Parser { | ||
Parser() {} | ||
|
||
public String parse(String input) { | ||
String DASH = "____________________________________________________________"; | ||
String[] inputArr = input.split(" "); | ||
String output = ""; | ||
String command = inputArr[0]; | ||
ArrayList<Task> taskList = TaskBank.getBank(); | ||
|
||
switch(command) { | ||
case "list": | ||
Action.showList(taskList); | ||
break; | ||
case "bye": | ||
Action.bye(); | ||
System.out.println(DASH); | ||
break; | ||
case "mark": | ||
try { | ||
int num = Integer.valueOf(inputArr[1]) - 1; | ||
taskList.get(num).markAsDone(); | ||
output = String.format("Nice! I've marked this task as done: %s\n", taskList.get(num)); | ||
} catch (NumberFormatException error) { | ||
output = "The index you have entered is not a number.\n"; | ||
} catch (ArrayIndexOutOfBoundsException error) { | ||
output = "The index you have entered is out of range.\n"; | ||
} | ||
break; | ||
case "unmark": | ||
try { | ||
int num = Integer.valueOf(inputArr[1]) - 1; | ||
taskList.get(num).markAsNotDone(); | ||
output = String.format("OK, I've marked this task as not done yet: %s\n", taskList.get(num)); | ||
} catch (NumberFormatException error) { | ||
output = "The index you have entered is not a number.\n"; | ||
} catch (ArrayIndexOutOfBoundsException error) { | ||
output = "The index you have entered is out of range.\n"; | ||
} | ||
break; | ||
case "todo": | ||
String remainingWordsTodo = ""; | ||
for (int i = 1; i < inputArr.length; i++) { | ||
remainingWordsTodo = remainingWordsTodo + " " + inputArr[i]; | ||
} | ||
Todo td = new Todo(remainingWordsTodo); | ||
taskList.add(td); | ||
output = String.format("Got it. I've added this task:\n %s\n", td); | ||
String noOfTaskTodo = String.format("Now you have %d tasks in the list.\n", taskList.size()); | ||
output = output + noOfTaskTodo; | ||
break; | ||
case "deadline": | ||
String remainingWordsDeadline = ""; | ||
String deadline = ""; | ||
for (int i = 1; i < inputArr.length; i++) { | ||
if (inputArr[i].equals("/by")) { | ||
for (int j = i + 1; j < inputArr.length; j++) { | ||
deadline = deadline + " " + inputArr[j]; | ||
} | ||
break; | ||
} else { | ||
remainingWordsDeadline = remainingWordsDeadline + " " + inputArr[i]; | ||
} | ||
} | ||
Deadline dl = new Deadline(remainingWordsDeadline, deadline); | ||
taskList.add(dl); | ||
output = String.format("Got it. I've added this task:\n %s\n", dl); | ||
String noOfTaskDeadline = String.format("Now you have %d tasks in the list.\n", taskList.size()); | ||
output = output + noOfTaskDeadline; | ||
break; | ||
case "event": | ||
String remainingWordsEvent = ""; | ||
String dayAndTime = ""; | ||
for (int i = 1; i < inputArr.length; i++) { | ||
if (inputArr[i].equals("/at")) { | ||
for (int j = i + 1; j < inputArr.length; j++) { | ||
dayAndTime = dayAndTime + " " + inputArr[j]; | ||
} | ||
break; | ||
} else { | ||
remainingWordsEvent = remainingWordsEvent + " " + inputArr[i]; | ||
} | ||
} | ||
Event e = new Event(remainingWordsEvent, dayAndTime); | ||
taskList.add(e); | ||
output = String.format("Got it. I've added this task:\n %s\n", e); | ||
String noOfTaskEvent = String.format("Now you have %d tasks in the list.\n", taskList.size()); | ||
output = output + noOfTaskEvent; | ||
break; | ||
case "delete": | ||
int num = Integer.valueOf(inputArr[1]) - 1; | ||
try { | ||
Task d = taskList.get(num); | ||
taskList.remove(num); | ||
output = String.format("Noted. I've removed this task:\n %s\n", d); | ||
String noOfTaskDelete = String.format("Now you have %d tasks in the list.\n", taskList.size()); | ||
output = output + noOfTaskDelete; | ||
} catch (NumberFormatException error) { | ||
output = "The index you have entered is not a number.\n"; | ||
} catch (ArrayIndexOutOfBoundsException error) { | ||
output = "The index you have entered is out of range.\n"; | ||
} | ||
break; | ||
case "help": | ||
output = "Here are all the commands available:\n" | ||
+ "list - to list out all the task\n" | ||
+ "bye - to end program\n" | ||
+ "todo <input something you want to do> - to add something you want to tasks\n" | ||
+ "deadline <input what is going be due> /by <input date> - to add a deadline to tasks\n" | ||
+ "event <input event description> /at <input date>\n - to add an event to tasks" | ||
+ "mark <input task number> - to mark task as done\n" | ||
+ "unmark <input task number> - to mark task as not done\n" | ||
+ "delete <input task number> - to delete task from tasks\n"; | ||
break; | ||
default: | ||
output = "invalid command! Use 'help' for help"; | ||
} | ||
|
||
return output; | ||
} | ||
} |
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,45 +1,30 @@ | ||
public class Task { | ||
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. It is possible to change Task to an abstract class? |
||
protected String description; | ||
protected boolean isDone; | ||
protected String sym; | ||
private String description; | ||
private boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
this.sym = " "; | ||
} | ||
|
||
public Task(String description, String sym) { | ||
this.description = description; | ||
this.isDone = false; | ||
this.sym = sym; | ||
public String getStatusIcon() { | ||
return isDone ? "X" : " "; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
System.out.println("Nice! I've marked this task as done:"); | ||
String output = String.format(" [%s][%s] %s", this.sym, this.getStatusIcon(), this.description); | ||
System.out.println(output); | ||
} | ||
|
||
public void markAsNotDone() { | ||
this.isDone = false; | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
String output = String.format(" [%s] %s", this.getStatusIcon(), this.description); | ||
System.out.println(output); | ||
} | ||
|
||
String getSym() { | ||
return this.sym; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("added: %s", description); | ||
return String.format("[%s] added: %s", this.getStatusIcon(), this.getDescription()); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.ArrayList; | ||
|
||
public class TaskBank { | ||
private static ArrayList<Task> bank = new ArrayList<Task>(); | ||
|
||
public TaskBank() {} | ||
|
||
public static void addTask(Task task) { | ||
bank.add(task); | ||
} | ||
|
||
public static void deleteTask(int index) { | ||
bank.remove(index); | ||
} | ||
|
||
public static ArrayList<Task> getBank() { | ||
return bank; | ||
} | ||
} |
Oops, something went wrong.
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.
I would opt for a more intuitive name rather than sym.
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.
Maybe you can change it to a more descriptive name such as symbol?