-
Notifications
You must be signed in to change notification settings - Fork 461
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
[Liu Han] ip #500
base: master
Are you sure you want to change the base?
[Liu Han] ip #500
Changes from 11 commits
556af3f
9676077
0d9ef52
5da01cb
0de5e80
3eed790
dac7f8e
880e4c0
2fe064a
a553d00
f5659ce
27413b8
ab182d3
a226e93
dbe31f4
ab2bbb2
d224115
ece43a0
eb63281
0e48f38
e98b02e
474467d
3f2cd52
1f03af6
dd62132
82c1254
fce0fb3
733de7f
aea7a3a
75e8974
f96b9c0
0948713
66c9edc
8a3b775
c8a71d1
4c5a763
82f3c2b
f22bafd
57cac3f
64a62a0
3493580
6a2a08d
068277a
16a3594
719d544
20602c7
4faf015
271d87c
d8c698b
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,84 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
enum Ability { | ||
BYE, | ||
LIST, | ||
MARK, | ||
UNMARK, | ||
TODO, | ||
DELETE | ||
} | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
String hello = " ____________________________________________________________\n" + | ||
" Hello! I'm Duke\n" + | ||
" What can I do for you?\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. Good minimalist design |
||
System.out.println(hello); | ||
|
||
List<Task> list = new ArrayList<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. Maybe you can change this variable name to tasks or something like that to make it clearer? |
||
|
||
Scanner sc = new Scanner(System.in); | ||
String input = sc.next(); | ||
|
||
while (!input.equals("bye")) { | ||
if (input.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. Consider using |
||
for (int i = 0; i < list.size(); i++) { | ||
System.out.println(i + 1 + "." + list.get(i)); | ||
} | ||
} else if (input.equals("mark")) { | ||
int number = sc.nextInt(); | ||
Task task = list.get(number - 1); | ||
task.markAsDone(); | ||
System.out.println(" ____________________________________________________________\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. You may consider placing line break before operator + 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. Also consider storing the separator as a constant |
||
" Nice! I've marked this task as done:\n " + | ||
task + | ||
"\n ____________________________________________________________"); | ||
} else if (input.equals("unmark")) { | ||
int number = sc.nextInt(); | ||
Task task = list.get(number - 1); | ||
task.markAsNotDone(); | ||
System.out.println(" ____________________________________________________________\n" + | ||
" Nice! I've marked this task as not done yet:\n " + | ||
task + | ||
"\n ____________________________________________________________"); | ||
} else { | ||
input = input + sc.nextLine(); | ||
System.out.println("Added: " + input); | ||
Task task = new Task(input); | ||
list.add(task); | ||
} | ||
input = sc.next(); | ||
} | ||
|
||
|
||
|
||
String strlst = "____________________________________________________________\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. Maybe you can change this variable to stringList or something like that to make it clearer? |
||
" Here are the tasks in your list:"; | ||
|
||
System.out.println(strlst); | ||
|
||
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 can remove a blank line here 😃 |
||
String todolist = "____________________________________________________________\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. Should this be |
||
" Got it. I've added this task:"; | ||
System.out.println(todolist); | ||
|
||
String todoEmpty = "____________________________________________________________\n" + | ||
" ☹ OOPS!!! The description of a todo cannot be empty.\n" + | ||
"____________________________________________________________\n"; | ||
System.out.println(todoEmpty); | ||
|
||
String unkown = "____________________________________________________________\n" + | ||
" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + | ||
"____________________________________________________________\n"; | ||
|
||
System.out.println(unkown); | ||
|
||
// if("delete") | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatus() { | ||
if (isDone) { | ||
return "X"; | ||
} else { | ||
return " "; | ||
} | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsNotDone() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + getStatus() + "] " + this.description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ then | |
fi | ||
|
||
# compile the code into the bin folder, terminates if error occurred | ||
if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java | ||
if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/Duke.java | ||
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 how you changed the accessibility where it is more specific 😄 |
||
then | ||
echo "********** BUILD FAILURE **********" | ||
exit 1 | ||
|
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.
Good use of enums for different commands!