-
Notifications
You must be signed in to change notification settings - Fork 114
[Liu Hao] ip #115
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
base: master
Are you sure you want to change the base?
[Liu Hao] ip #115
Changes from 10 commits
7305458
67c4b99
6e88ddf
124e27b
7eafffd
ce8c990
ca53856
bbbc899
a4c13d6
bf97069
33131f8
69fba63
88b3907
37af72d
af7427e
7c8bbb9
fd03a78
cf29cf0
d2a22fd
9d08a78
29ba5f7
b33d960
27ac37b
d9d5498
87c7068
a82c87a
2d1fff3
49f8cfa
c8afe18
34bd20e
f95bd41
a708d72
1d8d7a2
4f19c4a
b083a0a
66b8af4
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 + ")"; | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| public class Event extends Task{ | ||
| String from; | ||
| String to; | ||
| public Event(String description, String from, String to) { | ||
| super(description); | ||
| this.from = from; | ||
| this.to = to; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(){ | ||
| return "[E]" + super.toString() + "(from: " + from + " to: " + to + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| public class Task { | ||
| private final String description; | ||
| private boolean isCompleted; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isCompleted = false; | ||
| } | ||
|
|
||
| public void setCompleted(boolean completed) { | ||
| isCompleted = completed; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return isCompleted? "[X] " + description : "[ ]" + description; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import java.util.*; | ||
|
|
||
| public class Taylor { | ||
| public static void main(String[] args) { | ||
| Scanner sc = new Scanner(System.in); | ||
|
|
||
| final String line = "____________________________________________________________"; | ||
| System.out.println(line); | ||
| System.out.println("Hello! I'm Taylor"); | ||
| System.out.println("What can I do for you?"); | ||
| System.out.println(line); | ||
|
|
||
| String input = sc.nextLine(); | ||
| List<Task> tasks = new ArrayList<>(); | ||
| while(!input.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. For all the printing of the statements, maybe can put it in a method each. For instance, printTodoAdded() and the statement that the todo task have been added will be printed |
||
| 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. Is it possible to use a switch-case instead of if-else? |
||
| System.out.println(line); | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for(int i = 0; i < tasks.size(); i++) { | ||
|
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. Since tasks.size() is repeated used in all of the loops, perhaps can create a variable to store this value |
||
| System.out.println(i+1 + "." + tasks.get(i)); | ||
| } | ||
| System.out.println(line); | ||
| input = sc.nextLine(); | ||
| continue; | ||
| } | ||
|
|
||
| if(input.startsWith("mark")){ | ||
| String[] words = input.split(" "); | ||
| int index = Integer.parseInt(words[1])-1; | ||
| if(index<0 || index>=tasks.size()) { | ||
|
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 can place the code for checking in a method to allow easier reading |
||
| System.out.println(line); | ||
| System.out.println("Invalid index"); | ||
| System.out.println(line); | ||
| } else { | ||
| tasks.get(index).setCompleted(true); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(tasks.get(index)); | ||
| System.out.println(line); | ||
| } | ||
| input = sc.nextLine(); | ||
| continue; | ||
| } | ||
|
|
||
| if(input.startsWith("unmark")){ | ||
| String[] words = input.split(" "); | ||
| int index = Integer.parseInt(words[1])-1; | ||
| if(index<0 || index>=tasks.size()) { | ||
| System.out.println(line); | ||
| System.out.println("Invalid index"); | ||
| } else { | ||
| tasks.get(index).setCompleted(false); | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| System.out.println(tasks.get(index)); | ||
| System.out.println(line); | ||
| } | ||
| input = sc.nextLine(); | ||
| continue; | ||
| } | ||
|
|
||
| if(input.startsWith("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. Clear input handling for all the multiple types of commands (list, mark, unmark, todo, event, deadline) |
||
| Todo todo = new Todo(input.substring(4)); | ||
| // tasks.add(todo); | ||
| System.out.println(line); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + todo); | ||
| System.out.println("Now you have "+ tasks.size() +" tasks in the lists"); | ||
| System.out.println(line); | ||
| input = sc.nextLine(); | ||
| continue; | ||
| } | ||
|
|
||
| if(input.startsWith("event")){ | ||
| int from = input.indexOf("/from"); | ||
| int to = input.indexOf("/to"); | ||
| String description = input.substring(6,from); | ||
| String _from = input.substring(from+6,to); | ||
|
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. Preferably used another name instead of _from or _to as it is similar as from and to, which can be confusing |
||
| String _to = input.substring(to+4); | ||
| Event event = new Event(description,_from,_to); | ||
| tasks.add(event); | ||
| System.out.println(line); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + event); | ||
| System.out.println("Now you have "+ tasks.size() +" tasks in the lists"); | ||
| System.out.println(line); | ||
| input = sc.nextLine(); | ||
| continue; | ||
| } | ||
|
|
||
| if(input.startsWith("deadline")){ | ||
| int by = input.indexOf("/by"); | ||
| String description = input.substring(9,by); | ||
| String _by = input.substring(by+4); | ||
| Task task = new Deadline(description,_by); | ||
| tasks.add(task); | ||
| System.out.println(line); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + task); | ||
| System.out.println("Now you have "+ tasks.size() +" tasks in the lists"); | ||
| System.out.println(line); | ||
| input = sc.nextLine(); | ||
| continue; | ||
| } | ||
|
|
||
| System.out.println(line); | ||
| System.out.println("added: " + input); | ||
| System.out.println(line); | ||
| input = sc.nextLine(); | ||
| } | ||
| System.out.println(line); | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| System.out.println(line); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| public class TaylorException extends RuntimeException { | ||
| public TaylorException(String message) { | ||
| super(message); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| public class Todo extends Task { | ||
| public Todo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[T]" + super.toString(); | ||
| } | ||
| } |
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.
didn't do deep nesting, which is good code quality