-
Notifications
You must be signed in to change notification settings - Fork 114
[Hsien Kit] iP #102
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?
[Hsien Kit] iP #102
Changes from 9 commits
b2b7d6d
723a279
d0d3e24
09aa704
c7d834d
ebb8b59
00b8cea
2d82f1e
0246d23
75b5bd8
86d78e8
9031dda
1ffa5f8
c06df2b
f75d553
c068a61
c6c5306
b4e6a56
e6a1340
055c395
2c1f70c
c266c3d
6082be0
3c52351
2da60a6
5bdc397
a895954
95dee0d
662f20c
df3683b
4a6cba1
ef199ed
6d08b64
62581e7
8cb3432
1399fca
3f173eb
c660431
a08c526
c17532b
67a3381
af3bf76
637b76f
48a3c21
1a5e9aa
3d73a2e
69b6240
647b93c
2d63e0d
89bc0e2
aeb1168
40f5a8a
cefcaec
f26bf00
b65b3f0
340cc71
85f6afe
f55e8a3
d60cf51
59e642b
400c849
f35b164
c9ae249
1899673
2056c41
2f42622
3682108
467778d
5e3db0f
7584b2f
a9ce511
715514a
6777b16
8f57a0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| #.vscode Folder | ||
| /.vscode | ||
|
|
||
| # Class files | ||
| *.class | ||
|
|
||
| # IDEA files | ||
| /.idea/ | ||
| /out/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| public class Deadline extends Task { | ||
| private final String TYPE = "D"; | ||
| private String by; | ||
|
|
||
| public Deadline(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return TYPE; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return super.toString() + " (by: " + this.by + ")"; | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| public class Event extends Task { | ||
| private final String TYPE = "E"; | ||
|
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. Good use of declaring a constant to determine the type of task when returning from the getType method! |
||
| private String from; | ||
| private String to; | ||
|
|
||
| public Event(String description, String from, String to) { | ||
| super(description); | ||
| this.from = from; | ||
| this.to = to; | ||
| } | ||
|
|
||
| public String getfrom() { | ||
| return this.from; | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return TYPE; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return super.toString() + String.format(" (from: %s to: %s)", from, to); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| // Tasks that are done are marked with an X | ||
| public String getStatus() { | ||
| return (isDone ? "X" : " "); | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return this.description; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return null; | ||
| } | ||
|
|
||
| public void setDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s] %s", getStatus(), this.description); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| public class ToDo extends Task { | ||
| private final String TYPE = "T"; | ||
|
|
||
| public ToDo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return TYPE; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import java.util.Scanner; | ||
| import java.util.Arrays; | ||
|
|
||
| public class V { | ||
|
|
||
| private static final String LINE_SEPERATOR = "____________________________________________________________"; | ||
|
|
||
| // Print 2 line seperators between a block of text for cleaner CLI | ||
| public static void printBlock(String text) { | ||
| System.out.println(LINE_SEPERATOR); | ||
| System.out.println(text); | ||
| System.out.println(LINE_SEPERATOR); | ||
| } | ||
|
|
||
| public static void greet() { | ||
| String logo = " _ _ \n" | ||
| + "\\ \\ / / \n" | ||
| + " \\ \\ / / \n" | ||
| + " \\ \\_/ / \n" | ||
| + " \\___/ \n"; | ||
|
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. Consider to declare as public static final |
||
| System.out.print(logo); | ||
| printBlock("Hi I'm V\nWhat can I do for you?"); | ||
| } | ||
|
|
||
| public static void displayList(Task[] listOfTasks, int length) { | ||
| System.out.println(LINE_SEPERATOR); | ||
| for (int i = 0; i < length; i++) { | ||
| System.out.println(String.format("%d.[%s]%s", i + 1, | ||
| listOfTasks[i].getType(), listOfTasks[i])); | ||
| } | ||
| System.out.println(LINE_SEPERATOR); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| greet(); | ||
|
|
||
| boolean isOnline = true; | ||
| Task[] listOfTasks = new Task[100]; | ||
| int count = 0; | ||
| String temp; | ||
|
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. variable name "temp" can be more descriptive. |
||
| String description; | ||
| String by; | ||
| String[] timePeriod; | ||
| String from; | ||
| String to; | ||
| String line; | ||
| String[] lineArr; | ||
| Scanner input = new Scanner(System.in); | ||
|
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 respective variables here are hard to follow, maybe you could provide a comment for each of the variable's use case? |
||
|
|
||
| while (isOnline) { | ||
|
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. Good naming convention for your boolean variable! |
||
| line = input.nextLine(); | ||
| lineArr = line.trim().split(" "); | ||
| switch (lineArr[0]) { | ||
| case "bye": | ||
| input.close(); | ||
| isOnline = false; | ||
| break; | ||
|
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. Good use of boolean flag isOnline as it allows the program to have a clear flow and makes the code easy to understand. |
||
| case "list": | ||
| displayList(listOfTasks, count); | ||
| break; | ||
| case "mark": | ||
| int position = Integer.parseInt(lineArr[1]); | ||
| listOfTasks[position - 1].setDone(); | ||
| displayList(listOfTasks, count); | ||
| break; | ||
| case "todo": | ||
| description = String.join(" ", Arrays.copyOfRange(lineArr, 1, lineArr.length)); | ||
| listOfTasks[count] = new ToDo(description); | ||
| count++; | ||
| break; | ||
| case "event": | ||
| temp = String.join(" ", Arrays.copyOfRange(lineArr, 1, lineArr.length)); | ||
| description = temp.split("/from")[0]; | ||
| timePeriod = temp.split("/from")[1].split("/to"); | ||
| from = timePeriod[0]; | ||
| to = timePeriod[1]; | ||
| listOfTasks[count] = new Event(description, from, to); | ||
| System.out.println(listOfTasks[count]); | ||
| count++; | ||
| break; | ||
| case "deadline": | ||
| temp = String.join(" ", Arrays.copyOfRange(lineArr, 1, lineArr.length)); | ||
| description = temp.split("/by")[0]; | ||
| by = temp.split("/by")[1]; | ||
| listOfTasks[count] = new Deadline(description, by); | ||
| System.out.println(listOfTasks[count]); | ||
| count++; | ||
| break; | ||
| default: | ||
| System.out.println("Try again"); | ||
| break; | ||
| } | ||
| } | ||
| printBlock("See Ya"); | ||
| } | ||
|
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 could consider shortening your main method by breaking down the respective tasks into smaller methods |
||
| } | ||
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.
Consider declaring attributes as protected rather than private as it would be easier to facilitate extension of subclasses as the project progress.