-
Notifications
You must be signed in to change notification settings - Fork 200
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
[MichelleLiang0116] iP #200
base: master
Are you sure you want to change the base?
Changes from 16 commits
d2e1652
875214d
546d365
e5c4d7f
eaba19d
1097c11
2c0ac37
5e67ea1
0a7d6b0
0bd338f
dcbf7d7
fb2bb85
37ae4e7
341d75e
98769f2
166dbe5
90bb07f
e81c15c
189960a
53ca173
113e069
9922c6d
3ab622a
379a9f8
89744ec
aaf4920
8e2ca77
52f15f5
892e5de
ffc90fd
2691a37
aed8f4a
8a238be
649fcf5
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,13 @@ | ||
public class Deadline extends Task { | ||
protected final 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,63 @@ | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
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 in importing classes explicitly |
||
|
||
public class Duke { | ||
private final static ArrayList<Task> taskList = new ArrayList<>(); | ||
|
||
public static void main(String[] args) { | ||
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. Your main method feels a bit long, can consider modularizing it. According to the textbook, the recommendation is to have 30 LOC. |
||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
String lineBreak = "-----------------"; | ||
System.out.println(lineBreak + '\n' + "Hello! I'm Duke" + '\n' | ||
+ "What can I do for you?" + '\n' + lineBreak); | ||
String instruction; | ||
while (true) { | ||
Scanner myObj = new Scanner(System.in); | ||
instruction = myObj.nextLine(); | ||
if (instruction.equalsIgnoreCase("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. good job in using string.equalsIgnoreCase when comparing strings |
||
System.out.println(lineBreak + '\n' | ||
+ "Here are the tasks in your 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. Executing list command can be done on another java file. |
||
for (int i = 0; i < taskList.size(); i++) { | ||
System.out.println(i + 1 + "." + taskList.get(i).toString()); | ||
} | ||
System.out.println(lineBreak); | ||
} else if (instruction.equalsIgnoreCase("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. Can add comments between each command's execution to improve readability. |
||
System.out.println(lineBreak + '\n' | ||
+ "Bye. Hope to see you again soon!" + '\n' + lineBreak); | ||
break; | ||
} else if (instruction.toLowerCase().contains("mark")) { | ||
String[] split = instruction.split("\\s+"); | ||
int toMark = Integer.parseInt(split[1]); | ||
if (split[0].equalsIgnoreCase("mark")) { | ||
taskList.get(toMark - 1).markAsDone(); | ||
System.out.println("Nice! I've marked this task as done: "); | ||
} else { | ||
taskList.get(toMark - 1).markAsUnDone(); | ||
System.out.println("OK, I've marked this task as not done yet: "); | ||
} | ||
System.out.println(taskList.get(toMark - 1).toString() + '\n' + lineBreak); | ||
} else { | ||
Task t; | ||
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. Naming for this variable can be clearer. |
||
if (instruction.toLowerCase().contains("deadline")) { | ||
String description = instruction.substring(instruction.indexOf(' ') + 1, instruction.indexOf('/')); | ||
String ddl = instruction.substring(instruction.indexOf('/') + 1); | ||
String by = ddl.replace("by", ""); | ||
t = new Deadline(description, by); | ||
} else if (instruction.toLowerCase().contains("event")) { | ||
String substring = instruction.substring(instruction.indexOf(' ') + 1); | ||
String[] info = substring.split("/"); | ||
String from = info[1].replace("from", ""); | ||
String to = info[2].replace("to", ""); | ||
t = new Event(info[0], from, to); | ||
} else if (instruction.toLowerCase().contains("todo")) { | ||
String description = instruction.substring(instruction.indexOf(' ') + 1); | ||
t = new Todo(description); | ||
} else { | ||
t = new Task(instruction); | ||
} | ||
taskList.add(t); | ||
System.out.println(lineBreak + '\n' + "Got it. I've added this task:"); | ||
System.out.println('\t' + t.toString()); | ||
System.out.println("Now you have " + taskList.size() + " tasks in the list." + '\n' + lineBreak); | ||
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 in separating your output string to make your code look neat |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task { | ||
private final String from; | ||
private final 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,26 @@ | ||
public class Task { | ||
private final String description; | ||
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 restricting access to object variables. |
||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsUnDone() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + getStatusIcon() + "] " + 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(); | ||
} | ||
} |
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.
Inheritance to split task types is well done.