-
Notifications
You must be signed in to change notification settings - Fork 73
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
Ananda Lye iP #65
base: master
Are you sure you want to change the base?
Ananda Lye iP #65
Changes from 6 commits
f4af9fa
36e9b75
20de280
d454993
e5e44cd
6382975
69c2051
d4e6715
374e891
b716134
01fac6a
ad87997
e3eac76
110af11
b51628a
16a69ff
a5fc679
10dfbdf
5ed657a
b989408
31e4c3e
3c8e855
279c74f
13a6c1c
0b3f933
67d87bd
99c7b17
78b4752
66c26ad
f88b4c9
0ba4500
e868f96
e8b94c4
34826cc
46a26b3
d6c44f4
7862155
0bb1127
340cd7b
fa99f5b
be493f3
e72ccd1
0894cb3
8b25f16
58b9221
e93cada
c069fa0
95f8b2b
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,44 @@ | ||
import java.util.Scanner; | ||
import java.util.Arrays; | ||
|
||
public class Duke { | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
String greeting = "Hello! I'm Duke\n" + "What can I do for you?"; | ||
String goodbye = "Bye. Hope to see you again soon!"; | ||
System.out.println(greeting); | ||
|
||
Task[] tasklist = new Task[100]; | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
int flag = 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. variable names can be more descriptive to facilitate understanding. |
||
int index = 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. variable names can be more descriptive to facilitate understanding |
||
|
||
while (flag == 0) { | ||
String userinput = scanner.nextLine(); | ||
if (userinput.equals("bye")) { | ||
System.out.println(goodbye); | ||
flag = 1; | ||
} else if (userinput.equals("list")){ | ||
for (int i = 1; i <= index; i++) { | ||
System.out.print(i); | ||
System.out.print(".[" + tasklist[i-1].getStatusIcon() + "] " + tasklist[i-1].description + "\n"); | ||
} | ||
} else if (userinput.startsWith("done")){ | ||
String IndexOfItem = userinput.substring(5); | ||
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. use camelCase "indexOfItem" |
||
int ID = Integer.valueOf(IndexOfItem) - 1; | ||
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. use descriptive names to differentiate between int type and String type variable |
||
System.out.println("Nice! I've marked this task as done: "); | ||
System.out.println(tasklist[ID].markAsdone()); | ||
} else { | ||
System.out.println("added: " + userinput); | ||
tasklist[index] = new Task(userinput); | ||
index++; | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols | ||
} | ||
|
||
|
||
public String markAsdone () { | ||
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. use camelCase i.e. markAsDone |
||
this.isDone = true; | ||
return ("[" + this.getStatusIcon() + "] "+ this.description); | ||
} | ||
|
||
|
||
} |
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 using 'magic numbers'