-
Notifications
You must be signed in to change notification settings - Fork 361
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
[Qiu Qianhui] iP #376
base: master
Are you sure you want to change the base?
[Qiu Qianhui] iP #376
Changes from 1 commit
556af3f
2abf484
6e6c66f
8e390d2
63deb9f
638fe5e
fea77b0
a6d87e4
a57249e
1bc3b13
3d7c8f3
f308ef4
eaeedb9
db837df
1e9262f
e1c0c5e
858927b
c88a915
817bcee
6a8cd60
1a75274
f896222
5e84399
06a30bd
bc80cb8
2afc403
b05471e
0f3fe17
a7b2d76
895bae8
d3b4044
74bdb53
ff5718d
e9c03a4
6c72fb3
bc2e9a6
3e7ebc9
2c7366f
11b85c6
da2cede
9e36d1c
4ef0415
4b65663
f7f30c0
3a8547a
786fd75
9e53f70
85a4776
6882f68
ac99812
3b97191
9ff9abb
26f91eb
832d46a
f7536e5
abd962b
769a11d
b5d8dc4
8cd75f8
a19d9e3
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 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 |
---|---|---|
|
@@ -4,7 +4,7 @@ public class Duke { | |
|
||
private Scanner input = new Scanner(System.in); | ||
private Task tasks[] = new Task[100]; | ||
private int size = 0; | ||
private int taskIndex = 0; | ||
|
||
public void start() { | ||
String logo = "\t ____ _ \n" | ||
|
@@ -14,43 +14,88 @@ public void start() { | |
+ "\t |____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println(logo); | ||
System.out.println("\t Hello! I'm Duke"); | ||
System.out.println("\t What can I do for you?"); | ||
System.out.println("\t What can I do for you?\n"); | ||
} | ||
|
||
public void display() { | ||
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); | ||
} | ||
|
||
public void mark(String command) { | ||
int taskindex = Integer.parseInt(command.split(" ")[1]) - 1; | ||
tasks[taskindex].mark(); | ||
int index = Integer.parseInt(command.split(" ")[1]) - 1; | ||
tasks[index].mark(); | ||
} | ||
|
||
public void unmark(String command) { | ||
int taskindex = Integer.parseInt(command.split(" ")[1]) - 1; | ||
tasks[taskindex].unmark(); | ||
int index = Integer.parseInt(command.split(" ")[1]) - 1; | ||
tasks[index].unmark(); | ||
} | ||
|
||
public void list() { | ||
for (int i = 0; i < size; i++) { | ||
System.out.print("\t " + (i + 1) + "."); | ||
tasks[i].showTask(); | ||
for (int i = 0; i < taskIndex; i++) { | ||
System.out.print("\t " + (i + 1) + "." + tasks[i].toString() + "\n"); | ||
} | ||
System.out.print("\n"); | ||
} | ||
|
||
public void addTask(Task task) { | ||
tasks[taskIndex] = task; | ||
taskIndex++; | ||
System.out.println("\t Got it. I've added this task:\n" | ||
+ "\t\t "+ tasks[taskIndex - 1].toString() | ||
+ "\n\t Now you have " + taskIndex + " tasks in the list.\n"); | ||
} | ||
public void todo(String command) { | ||
String description = command.split(" ", 2)[1]; | ||
Todo todo = new Todo(description); | ||
addTask(todo); | ||
} | ||
|
||
public void deadline(String command) { | ||
String info[] = command.split(" ", 2)[1].split(" /by "); | ||
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 we could use a variable name that indicates this is an array? Also, remember to have the square brackets right after the data type~! (String[]) |
||
String description = info[0]; | ||
String by = info[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. Maybe instead of just "by", we can use a variable name that indicates that this is a date? |
||
Deadline deadline = new Deadline(description, by); | ||
addTask(deadline); | ||
} | ||
|
||
public void event(String command) { | ||
String info[] = command.split(" ", 2)[1].split(" /from "); | ||
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. Ooh I like your clever usage of split to distinguish between /to argument and /from argument! |
||
String description = info[0]; | ||
String dates[] = info[1].split(" /to "); | ||
String from = dates[0]; | ||
String to = dates[1]; | ||
|
||
Event event = new Event(description, from, to); | ||
addTask(event); | ||
} | ||
|
||
public void run() { | ||
start(); | ||
while (true) { | ||
String command = input.nextLine(); | ||
if (command.equals("bye")) { | ||
display(); | ||
System.out.println("\t Bye. Hope to see you again soon!"); | ||
break; | ||
} else if (command.equals("list")) { | ||
display(); | ||
list(); | ||
} else if (command.startsWith("mark")) { | ||
display(); | ||
mark(command); | ||
} else if (command.startsWith("unmark")) { | ||
display(); | ||
unmark(command); | ||
} else { | ||
tasks[size] = new Task(command); | ||
size++; | ||
System.out.println("\t added: " + command); | ||
} else if (command.startsWith("todo")) { | ||
display(); | ||
todo(command); | ||
} else if (command.startsWith("deadline")) { | ||
display(); | ||
deadline(command); | ||
} else if(command.startsWith("event")) { | ||
display(); | ||
event(command); | ||
} | ||
} | ||
} | ||
|
@@ -60,5 +105,3 @@ public static void main(String[] args) { | |
duke.run(); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Event extends Task{ | ||
protected String from; | ||
protected 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,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.
I like what you did here - indenting and spacing a sentence into parts that are more readable!