-
Notifications
You must be signed in to change notification settings - Fork 267
[Sim Jia Ming] iP #316
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
base: master
Are you sure you want to change the base?
[Sim Jia Ming] iP #316
Changes from 9 commits
d839859
6b8c2f2
778d1e0
8009280
8fa8a55
3357573
f2fabf0
a210a0f
8a7ee50
a51d3f3
5b8561d
3d7329e
5dcf7b0
6b65fea
4ab3dac
832f67b
507c6a3
7f7f081
b8d7f64
70d14c8
8695409
4ac330a
26bba93
95823e5
81232fa
726b27f
52b6b7c
dee52c7
e1ccf9d
3c83a87
a018811
fe06e8f
b3a9390
53330a6
8cfee6f
4aaed72
25c776d
807bab5
ba460f1
ae805b1
70a7cf8
b5a30d2
6992122
9e89a02
f56ff47
9181b89
a914019
046d881
000f5a1
8ed816b
b7ec4fe
09593f8
98566a3
d232468
4352935
f3191a8
3bc0613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Action { | ||
|
|
||
| Action() {} | ||
|
|
||
| void greet() { | ||
| String greet = "Hello! I'm JiaMing\nWhat can I do for you?\n"; | ||
| System.out.println(greet); | ||
| } | ||
|
|
||
| void echo(String phrase) { | ||
| System.out.println(phrase); | ||
| } | ||
|
|
||
| void bye() { | ||
| String bye = "Bye. Hope to see you again soon!\n"; | ||
| System.out.println(bye); | ||
| } | ||
|
|
||
| void showList(ArrayList<Task> arrlst) { | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < arrlst.size(); i++) { | ||
| String output = String.format("%d.[%s][%s]%s\n", i + 1, arrlst.get(i).sym, | ||
| arrlst.get(i).getStatusIcon(), arrlst.get(i).description); | ||
| System.out.println(output); | ||
| } | ||
| } | ||
|
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. Could use a javadocs documentation. |
||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "this is an Action (Parent)"; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| public class Deadline extends Task { | ||
| protected final String sym = "D"; | ||
| protected String day; | ||
|
|
||
| Deadline (String description, String day) { | ||
| super(description); | ||
| this.day = day; | ||
| } | ||
|
|
||
| @Override | ||
| String getSym() { | ||
|
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. I would opt for a more intuitive name rather than sym. 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.
Maybe you can change it to a more descriptive name such as symbol? |
||
| return this.sym; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s][%s]%s (by:%s)", sym, super.getStatusIcon(), super.description, this.day); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,107 @@ | ||
| // enums not applicable | ||
|
|
||
| import java.util.Scanner; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Scanner sc = new Scanner(System.in); | ||
| ArrayList<Task> arrlst = new ArrayList<>(); | ||
| String DASH = "____________________________________________________________"; | ||
|
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. This works too, but UI can be separated into a class for cleanliess |
||
| Action act = new Action(); | ||
|
|
||
| act.greet(); | ||
|
|
||
| while (sc.hasNext()) { | ||
| String phrase = sc.nextLine(); | ||
| System.out.println(DASH); | ||
|
|
||
| if (phrase.equals("list")) { | ||
|
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. Perhaps you can consider using a switch statement instead? 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. The code here is pretty long, but you will get to break it down later as you progress with the iP. Consider doing the printing in separate functions and get your switch statement to invoke those print functions instead. |
||
| 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]; | ||
| } | ||
| } | ||
|
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. Could use comments in places like these to explain what the code is doing (i.e. splitting up the user input) as it may not be apparent on first sight. |
||
| 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 | ||
|
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. You can consider changing the parameter name to just |
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| public class Event extends Task { | ||
| protected final String sym = "E"; | ||
| private String dayAndTime; | ||
|
|
||
| Event (String description, String dayAndTime) { | ||
| super(description); | ||
| this.dayAndTime = dayAndTime; | ||
| } | ||
|
|
||
| @Override | ||
| String getSym() { | ||
| return this.sym; | ||
| } | ||
|
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. May I check what is the purpose of this override? Same with deadline and todo classes. Seems redundant as the getSym() in Task is the same. |
||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s][%s]%s (at:%s)", sym, super.getStatusIcon(), super.description, this.dayAndTime); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| 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; | ||
|
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. While protected may appear sufficient, these attributes can still be accessible by other functions once you start putting them into packages. Consider changing your attributes to |
||
| protected boolean isDone; | ||
| protected String sym; | ||
|
|
||
| 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" : " "); // mark done task with X | ||
| } | ||
|
|
||
| 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() { | ||
|
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. Missing |
||
| return this.sym; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("added: %s", description); | ||
|
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. I think you should change your toString() method to print out the |
||
| } | ||
|
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. Could use some javadocs documentation as Task is the parent class. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| public class Todo extends Task { | ||
| protected final String sym = "T"; | ||
|
|
||
| Todo (String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| @Override | ||
| String getSym() { | ||
| return this.sym; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s][%s]%s", sym, super.getStatusIcon(), super.description); | ||
| } | ||
|
|
||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| Hello from | ||
| ____ _ | ||
| | _ \ _ _| | _____ | ||
| | | | | | | | |/ / _ \ | ||
| | |_| | |_| | < __/ | ||
| |____/ \__,_|_|\_\___| | ||
| Hello! I'm JiaMing | ||
| What can I do for you? | ||
|
|
||
| ____________________________________________________________ | ||
| Got it. I've added this task: | ||
| [T][ ] borrow book | ||
| Now you have 1 tasks in the list. | ||
| ____________________________________________________________ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| todo borrow book |
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.
Looks clean!