-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Zhang Yubin] ip #471
base: master
Are you sure you want to change the base?
[Zhang Yubin] ip #471
Changes from 7 commits
d839859
a320dbd
56dd70a
98b4bdc
5bf86fe
15b129b
9c82281
79c9bdf
010e34e
0cc48f4
e4d564e
e1e5885
a046802
13513a0
e23ab33
9e90dc7
d9cd2c8
6f75690
a8adc43
ac088aa
6f56ccd
5ab9d28
3e1041e
55e5b87
8397082
14e72e8
1a5e30c
4b75f2c
c3b7bdd
192bb10
a4539eb
8d35eac
fec1ca4
99fe33e
67a5a7a
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,84 @@ | ||
import com.sun.source.tree.DoWhileLoopTree; | ||
|
||
import java.util.ArrayList; | ||
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 line = "____________________________________________________________"; | ||
ArrayList<Task> task = new ArrayList<>(); | ||
System.out.println("Hello from\n" + logo + line + "\nWhat can I do for you?\n" + line); | ||
|
||
String input; | ||
Scanner s = new Scanner(System.in); | ||
input = s.nextLine(); | ||
|
||
while(!input.equals("bye")) { | ||
String[] parts = input.split(" "); | ||
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. Might be cleaner to change to switch statements |
||
int i = 1; | ||
System.out.println(line); | ||
System.out.println("Here are the tasks in your list:"); | ||
for(Task t: task) { | ||
System.out.println(i + "." + t.toString()); | ||
i++; | ||
} | ||
System.out.println(line); | ||
} else if (parts[0].equals("done")) { | ||
int index = Integer.valueOf(parts[1]); | ||
Task thisTask = task.get(index - 1); | ||
thisTask.markDone(); | ||
System.out.println(line); | ||
System.out.println("Nice! I've marked this task as done:\n" + thisTask.toString()); | ||
System.out.println(line); | ||
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 for this portion can create an additional class(Example UI) to do all this line of code for you, and just need to call that function from the class so that it looks much neater. Can also be done so on your other if-else statements |
||
} else if (parts[0].equals("delete")) { | ||
int index = Integer.valueOf(parts[1]); | ||
Task thisTask = task.remove(index - 1); | ||
System.out.println(line); | ||
System.out.println("Noted I've removed this task:\n" + thisTask.toString()); | ||
System.out.println("Now you have " + task.size() + " tasks in your list"); | ||
System.out.println(line); | ||
} else if (parts.length == 1) { | ||
System.out.println(line); | ||
System.out.println("OOPS!!! The description of a " + parts[0] + " cannot be empty."); | ||
System.out.println(line); | ||
} else if (parts[0].equals("deadline")){ | ||
String[] part2 = input.split("/by "); | ||
String description = part2[0].split("deadline ")[1]; | ||
Task deadline = new Deadline(description, part2[1]); | ||
System.out.println(line + "\n" + "added: " + deadline.toString()); | ||
task.add(deadline); | ||
System.out.println("Now you have " + task.size() + " tasks in your list"); | ||
System.out.println(line); | ||
} else if (parts[0].equals("event")){ | ||
String[] part2 = input.split("/at "); | ||
String description = part2[0].split("event ")[1]; | ||
Task event = new Event(description, part2[1]); | ||
System.out.println(line + "\n" + "added: " + event.toString()); | ||
task.add(event); | ||
System.out.println("Now you have " + task.size() + " tasks in your list"); | ||
System.out.println(line); | ||
} else if (parts[0].equals("todo")){ | ||
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 there should be a space between ")" and "{", so ) { |
||
String[] part2 = input.split("/"); | ||
String description = part2[0].split("todo ")[1]; | ||
Task todo = new Todo(description); | ||
System.out.println(line + "\n" + "added: " + todo.toString()); | ||
task.add(todo); | ||
System.out.println("Now you have " + task.size() + " tasks in your list"); | ||
System.out.println(line); | ||
} else { | ||
System.out.println(line); | ||
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
System.out.println(line); | ||
} | ||
input = s.nextLine(); | ||
} | ||
|
||
System.out.println(line + "\nBye. Hope to see you again soon!\n" + line); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Event extends Task { | ||
|
||
protected String at; | ||
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. Might be good to use a more desceiptive name for the variable |
||
|
||
public Event(String description, String at) { | ||
super(description); | ||
this.at = at; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (at: " + at + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
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. Ternary operators might look cleaner when seperated into multiple lines, and there is no need for the brackets. |
||
} | ||
|
||
public void markDone(){ | ||
this.isDone = true; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return "[" + this.getStatusIcon() + "] " + this.description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Todo extends Task { | ||
|
||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
____________________________________________________________ | ||
What can I do for you? | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
added: [T][ ] borrow book | ||
Now you have 1 tasks in your list | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
added: [D][ ] return book (by: Sunday) | ||
Now you have 2 tasks in your list | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
added: [E][ ] project meeting (at: Mon 2-4pm) | ||
Now you have 3 tasks in your list | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
added: [D][ ] return book (by: June 6th) | ||
Now you have 4 tasks in your list | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
added: [T][ ] join sports club | ||
Now you have 5 tasks in your list | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Nice! I've marked this task as done: | ||
[E][X] project meeting (at: Mon 2-4pm) | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Bye. Hope to see you again soon! | ||
____________________________________________________________ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
todo borrow book | ||
deadline return book /by Sunday | ||
event project meeting /at Mon 2-4pm | ||
deadline return book /by June 6th | ||
todo join sports club | ||
done 3 | ||
bye |
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.
Should this be more specific as to what it refers to?