-
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
[janelleenqi] iP #75
base: master
Are you sure you want to change the base?
[janelleenqi] iP #75
Changes from 6 commits
a4564e4
860d878
35b72fc
5fc8ba6
8e02823
6b19f57
aebc096
17570b2
10bcaae
b503333
5bae015
2702b6e
7796691
39b457c
573e246
bf1f72b
7087e36
0609792
e41f732
6c7aeb7
4320721
f6e4a2d
5dc30d9
e0a2e01
3eb76bc
25200f0
746312f
37b5bb1
ed9f860
022d97d
e51e000
36fcba8
0641727
af7f54c
0437cfb
6494a32
52f898d
39ad792
652c9b2
51f7a9f
4bcd01d
801ed78
39eda3c
18a6643
bf62341
56321ce
48815a3
ef5a710
2da6307
49d2924
772d5cf
f1b66a6
364d48d
ad80c66
1818f2f
3190778
b99923f
1109f04
3ad68bf
de661a4
a466466
4342a65
698d964
41f428d
3d28a78
b8fe251
54c9b4c
afa9433
3d45534
1845d33
56970bd
688c7da
3ed4739
a1a0256
f21791f
e1e19fb
5c566bd
2e094bf
4e9d393
05973a4
2294806
bfe863a
bef32d4
bd4a715
e27b225
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,10 +1,54 @@ | ||||||||
import java.util.Scanner; | ||||||||
|
||||||||
public class Duke { | ||||||||
public static void main(String[] args) { | ||||||||
String logo = " ____ _ \n" | ||||||||
+ "| _ \\ _ _| | _____ \n" | ||||||||
+ "| | | | | | | |/ / _ \\\n" | ||||||||
+ "| |_| | |_| | < __/\n" | ||||||||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||||||||
System.out.println("Hello from\n" + logo); | ||||||||
String logo = " _ _ \n" | ||||||||
+ "| | _ _| | _____ \n" | ||||||||
+ "| | | | | | |/ / _ \\\n" | ||||||||
+ "| |___| |_| | < __/\n" | ||||||||
+ "|_____|\\__,_|_|\\_\\___|\n"; | ||||||||
System.out.println("Hello! I'm\n" + logo); | ||||||||
System.out.println("What can I do for you?"); | ||||||||
|
||||||||
Task[] theList = new Task[100]; | ||||||||
Scanner userInput = new Scanner(System.in); | ||||||||
int counter = 0; | ||||||||
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 the counter variable could be more descriptive to allow the reader to understand what it is counting. |
||||||||
|
||||||||
String echo = userInput.nextLine(); | ||||||||
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. Can consider making some changes to the following variables:
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 using a more suitable name for echo so that it is more descriptive for the reader. |
||||||||
|
||||||||
while (!echo.equals("bye")) { | ||||||||
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 declaring static final constants for each command (e.g. bye, list, mark) so that they can be easily referenced and updated for future use
Suggested change
|
||||||||
String[] words = echo.split(" "); //to identify usage of features "mark" & "unmark" | ||||||||
|
||||||||
if (echo.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. Could potentially use a switch if possible to make the code more readable. |
||||||||
System.out.println("Here are the tasks in your list:"); | ||||||||
for (int i = 0; i < counter; i += 1) { | ||||||||
System.out.print((i + 1) + "."); | ||||||||
theList[i].printTask(); | ||||||||
} | ||||||||
|
||||||||
} else if (words[0].equals("mark")) { | ||||||||
int taskNumber = Integer.parseInt(words[1]) - 1; | ||||||||
System.out.println("Woohoo! You have accomplished:"); | ||||||||
theList[taskNumber].markAsDone(); | ||||||||
theList[taskNumber].printTask(); | ||||||||
|
||||||||
} else if (words[0].equals("unmark")) { | ||||||||
int taskNumber = Integer.parseInt(words[1]) - 1; | ||||||||
System.out.println("HA! You still have to complete:"); | ||||||||
theList[taskNumber].markAsIncomplete(); | ||||||||
theList[taskNumber].printTask(); | ||||||||
|
||||||||
} else { | ||||||||
theList[counter] = new Task(echo); | ||||||||
System.out.println("added: " + echo); | ||||||||
counter += 1; | ||||||||
} | ||||||||
|
||||||||
echo = userInput.nextLine(); | ||||||||
} | ||||||||
|
||||||||
System.out.println("Bye. Hope to see you again soon!"); | ||||||||
|
||||||||
userInput.close(); | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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. Good job for using good coding standards in this file! Descriptive names are used for functions and variables |
||
protected String taskName; | ||
protected boolean isDone; | ||
|
||
public Task(String taskName) { | ||
this.taskName = taskName; | ||
this.isDone = false; | ||
} | ||
|
||
public void printTask() { | ||
System.out.println("[" + getStatusIcon() + "] " + taskName); | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public void markAsDone() { | ||
isDone = true; | ||
} | ||
|
||
public void markAsIncomplete() { | ||
isDone = 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. I like your use of descriptive names to make the code clear and concise. |
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 using a more descriptive name such as
taskList
instead oftheList