-
Notifications
You must be signed in to change notification settings - Fork 78
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
[Dexter Hoon] iP #68
base: master
Are you sure you want to change the base?
[Dexter Hoon] iP #68
Changes from 1 commit
c606c3c
e3f01fa
3afcb6b
184e708
cf80b82
1afaaf1
e331bb9
951a3e6
7a7066d
32601dd
ff60709
3550db1
ae095d1
31437f8
511f4d2
eb7f6ae
b168238
4194ba3
8365fc3
44587d6
c7bcaaa
17b65ef
1933454
41ce6df
88bace6
94bcc13
a49e395
23738a8
3dab5c7
425e388
b6ecfbe
eeee528
d7ccba5
361eb39
4935bba
7f3c631
d140956
2d45aff
310e2b4
61e0f3c
4c9970f
51959a1
64c21f4
4b5849c
4bac978
ef54d91
c63d05e
7efbd2b
4a0b8b8
151f23c
1f42faa
efc4ab2
036f277
f67cbbf
6cc4255
e4f770e
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
public class Alan { | ||
|
||
public static void printGreet() { | ||
public static void printGreetingMessage() { | ||
printHorizontalLine(); | ||
String man = " @/\n" + | ||
"/| \n" + | ||
|
@@ -14,7 +14,7 @@ public static void printGreet() { | |
printHorizontalLine(); | ||
} | ||
|
||
public static void printExit() { | ||
public static void printExitMessage() { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
|
@@ -23,10 +23,10 @@ public static void printHorizontalLine() { | |
} | ||
|
||
public static void main(String[] args) { | ||
Task[] taskList = new Task[101]; | ||
int currentTaskListIndex = 1; | ||
Task[] tasks = new Task[101]; | ||
int currentTasksIndex = 1; | ||
|
||
printGreet(); | ||
printGreetingMessage(); | ||
DextheChik3n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
String userInput = " "; | ||
DextheChik3n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Scanner in = new Scanner(System.in); | ||
|
@@ -37,35 +37,40 @@ public static void main(String[] args) { | |
userInput = in.nextLine(); | ||
|
||
printHorizontalLine(); | ||
|
||
if (userInput.equals("bye")) { | ||
printExit(); | ||
} else if (userInput.equals("list")) { //print the tasks in the lists | ||
printExitMessage(); | ||
} else if (userInput.equals("list")) { | ||
//print the tasks in the lists | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 1; i < currentTaskListIndex; i++) { | ||
System.out.println((i) + ". [" + taskList[i].getStatusIcon() + "] " + taskList[i].getDescription()); | ||
for (int i = 1; i < currentTasksIndex; i++) { | ||
System.out.println((i) + ". [" + tasks[i].getStatusIcon() + "] " + tasks[i].getDescription()); | ||
} | ||
} else if (userInput.startsWith("mark")) { //mark tasks as done | ||
} else if (userInput.startsWith("mark")) { | ||
//mark tasks as done | ||
String[] words = userInput.split(" "); | ||
|
||
taskList[Integer.parseInt(words[1])].setDone(true); | ||
tasks[Integer.parseInt(words[1])].setDone(true); | ||
|
||
System.out.println("Alright! I've marked this task as done:"); | ||
System.out.println("\t[" + taskList[Integer.parseInt(words[1])].getStatusIcon() + "] " + | ||
taskList[Integer.parseInt(words[1])].getDescription()); | ||
System.out.println("\t[" + tasks[Integer.parseInt(words[1])].getStatusIcon() + "] " + | ||
tasks[Integer.parseInt(words[1])].getDescription()); | ||
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. Try to avoid complicated expressions. 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. Yeah very true... I will follow what someone else suggested by using more variables to simplify the statement |
||
|
||
} else if (userInput.startsWith("unmark")) { //unmark tasks as undone | ||
} else if (userInput.startsWith("unmark")) { | ||
//unmark tasks as undone | ||
String[] words = userInput.split(" "); | ||
|
||
taskList[Integer.parseInt(words[1])].setDone(false); | ||
tasks[Integer.parseInt(words[1])].setDone(false); | ||
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 you rename this line as a variable, seeing as you use it later in your code? 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. Thanks for the suggestion... I think it could be helpful to do this as it can make my code neater :D |
||
|
||
System.out.println("Ok, I've marked this task as not done yet:"); | ||
System.out.println("\t[" + taskList[Integer.parseInt(words[1])].getStatusIcon() + "] " + | ||
taskList[Integer.parseInt(words[1])].getDescription()); | ||
System.out.println("\t[" + tasks[Integer.parseInt(words[1])].getStatusIcon() + "] " + | ||
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 making some variables statement could make this less verbose 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 agree... will probably do that since it does look very complex and hard to understand what is going on |
||
tasks[Integer.parseInt(words[1])].getDescription()); | ||
|
||
} else { //add a new task to the list | ||
} else { | ||
//add a new task to the list | ||
Task task = new Task(userInput); | ||
taskList[currentTaskListIndex] = task; | ||
currentTaskListIndex++; | ||
tasks[currentTasksIndex] = task; | ||
currentTasksIndex++; | ||
System.out.println("added: " + userInput); | ||
} | ||
|
||
|
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.
Try to avoid long methods. You can try to extract part of the code into other 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.
Alright sure I can try to break the long method into smaller methods to handle each of the commands which can make it easier to debug and organise my code