-
Notifications
You must be signed in to change notification settings - Fork 482
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
[Song Bingxi] iP #581
base: master
Are you sure you want to change the base?
[Song Bingxi] iP #581
Changes from 18 commits
28ad2b8
ed6d4d2
d70a89c
fb563f9
73ab967
6fabf95
ab634e9
0443851
03e576d
2dddc56
da7ab38
0d3fb8f
71a526c
32d61ff
c2dd4b6
7bb853f
946a420
f3c38a1
af19be1
6e02da2
83987f8
6940826
fe6a5b7
9de4371
610f3fe
31194bf
12dd515
886b3f9
a2d3388
41fec5f
5e9ba09
9f6fd76
cf1d3ca
27ad786
1006fc6
d31bda6
7758e65
f898eca
4cb7eeb
39bad21
e244086
4b37e32
972ffc3
a0857e9
353e7fa
2df0253
61f1ef8
491f621
e76b225
7bc4e60
e13c035
1036641
6a3d9e0
3eca81e
40de3b0
a75bed8
a8b6457
43420cb
e49cf6a
67e4213
86da9bb
959ecd6
4910fd1
d146702
5675ef8
fedbd57
8abb331
cd198b9
467d521
22c6628
4311adb
b38037f
89fb8e7
c57515b
8e017d7
e86be9c
ee5e6c4
6de1fc4
6b974b9
c7aa0b6
ffc71e8
34a9d61
d4ddaba
c89265c
e220b59
327b91a
b49ec01
b3cbbe2
58e2c30
8275eb4
ff53235
0e728ce
70b6d00
f97962d
528051b
235bcb6
2788070
7ba81c4
2028dcc
211d3cc
7a7758e
39eb73a
1de9d95
17deebc
a961434
b423a97
f3d5e2c
45c937e
83c7fc7
c73b593
320f1cc
51de6f6
e9ab221
194213f
838daa4
81d83fc
157b849
7481b12
358f337
9dfde0e
c0d5fa0
0b9286a
be95480
e205416
e040f5c
52a9a05
2e83549
0805e76
4ae78e2
3768770
6e0c6ee
78e06a8
effae22
85b5fe1
d632419
e9d938d
d0b01b6
b3d12f6
7c31503
f5ceeda
a3a41f8
45a6206
a5029d5
f0d90f6
abbd6f3
3cbd8d8
7d35804
75c053e
84f331d
f4321f0
8b9f254
b31387c
82e28de
0ad66b8
e0e610e
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,172 @@ | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
enum TASK_TYPE {TODO, DEADLINE, EVENT} | ||
public class Dan { | ||
|
||
private final static String greets = "\nDan: \n"; | ||
private static MyList tasks = new MyList(100); | ||
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 a class name like TaskList would be more intuitive than MyList? |
||
private final static String[] commands = new String[] { | ||
"toDo [TASK]", | ||
"deadline [TASK] /by [DEADLINE]", | ||
"event [TASK] /from [START_TIME] /to [END_TIME]", | ||
"list", "bye", | ||
"mark [TASK_ID]", "unmark [TASK_ID]" | ||
}; | ||
|
||
|
||
public static void main(String[] args) { | ||
hello(); | ||
chat(); | ||
goodbye(); | ||
} | ||
|
||
|
||
|
||
private static void chat() { | ||
String text; | ||
String[] texts; | ||
String command; | ||
a: while (true) { | ||
try { | ||
text = new Scanner(System.in).nextLine(); | ||
texts = text.split(" "); | ||
command = texts[0].toLowerCase(); | ||
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 consider extracting the commands to a Parser or Command class |
||
switch (command) { | ||
case "bye": | ||
break a; | ||
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 it would be better if you can extract these 'instructions' out to a Ui class |
||
case "list": | ||
list(); | ||
break; | ||
case "mark": | ||
if (!mark(texts[1])) | ||
continue; | ||
break; | ||
case "unmark": | ||
if (!unmark(texts[1])) | ||
continue; | ||
break; | ||
case "todo": | ||
addTask(text, TASK_TYPE.TODO); | ||
break; | ||
case "deadline": | ||
addTask(text, TASK_TYPE.DEADLINE); | ||
break; | ||
case "event": | ||
addTask(text, TASK_TYPE.EVENT); | ||
break; | ||
case "delete": | ||
deleteTask(Integer.parseInt(texts[1])); | ||
break; | ||
default: | ||
throw new DanException("Incorrect command"); | ||
} | ||
} catch (Exception e) { | ||
if (e instanceof DanException ) { | ||
System.out.println(greets + " 你输入的东西不太对哦!"); | ||
} else if (e instanceof IndexOutOfBoundsException) { | ||
System.out.println(greets + " 输入格式不对!"); | ||
} else if (e instanceof IllegalArgumentException) { | ||
System.out.println(greets + " 输入格式不对!"); | ||
} | ||
System.out.println(" 你可以跟我说:\n" + Arrays.toString(commands) + "\n"); | ||
} | ||
} | ||
} | ||
|
||
private static void deleteTask(int i) { | ||
Task removedTask = tasks.remove(i); | ||
System.out.println( | ||
greets + | ||
" 好啦,帮你擦掉了一条任务哦:\n " + removedTask + | ||
"\n 现在还剩下" + tasks.size() + "项任务哦!\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. only english is recommended for coding! |
||
); | ||
} | ||
|
||
public static void addTask(String text, TASK_TYPE id) throws IndexOutOfBoundsException { | ||
String[] texts = text.split("/"); | ||
for (int i = 0; i < texts.length; i++) { | ||
texts[i] = texts[i].trim(); | ||
} | ||
Task newTask = null; | ||
String description; | ||
switch (id) { | ||
case 1 : | ||
description = texts[0].substring(5); | ||
newTask = new ToDo(description); | ||
break; | ||
case 2 : | ||
description = texts[0].substring(9); | ||
String deadline = texts[1].substring(3); | ||
newTask = new Deadline(description, deadline); | ||
break; | ||
case 3 : | ||
description = texts[0].substring(5); | ||
String start = texts[1].substring(5); | ||
String end = texts[2].substring(3); | ||
newTask = new Event(description, start, end); | ||
break; | ||
} | ||
tasks.add(newTask); | ||
System.out.println( | ||
greets + " 新任务:\n " + newTask + | ||
"!\n 现在有" + tasks.size() + "项任务哦!\n" | ||
); | ||
} | ||
|
||
private static boolean mark(String taskId) { | ||
Task currTask = markTask(taskId, 0); | ||
if (currTask == null) { | ||
System.out.println(greets + " 这个已经做完了哦!\n"); | ||
return false; | ||
} | ||
System.out.println( | ||
greets + " 哟 做完啦?帮你标记好了!\n " + | ||
currTask + "\n" | ||
); | ||
return true; | ||
} | ||
|
||
private static boolean unmark(String taskId) { | ||
Task currTask = markTask(taskId, 1); | ||
if (currTask == null) { | ||
System.out.println(greets + " 这个没标记过哦!\n"); | ||
return false; | ||
} | ||
System.out.println( | ||
greets + " 啊?没做完啊 是不小心手滑了么?\n " + | ||
currTask + "\n" | ||
); | ||
return true; | ||
} | ||
|
||
private static Task markTask(String taskId, int funcId) { | ||
Task currTask = tasks.get(Integer.parseInt(taskId) - 1); | ||
boolean succ = currTask.mark(funcId); | ||
if (!succ) { | ||
return null; | ||
} | ||
return currTask; | ||
} | ||
|
||
private static void list() { | ||
System.out.println( | ||
greets + " 你还有些要做的事情呢 我看看有什么吧!\n" + | ||
tasks.toString() + "\n" | ||
); | ||
} | ||
|
||
public static void hello() { | ||
System.out.println( | ||
greets + | ||
" 我是小丹!\n" + | ||
" 有什么可以要帮忙可以跟我说!\n" | ||
); | ||
} | ||
public static void goodbye() { | ||
System.out.println( | ||
greets + | ||
" 拜拜啦!下次见!\n" | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import java.util.InputMismatchException; | ||
|
||
public class DanException extends InputMismatchException { | ||
|
||
public DanException(String s) { | ||
super(s); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.util.Date; | ||
|
||
public class Deadline extends Task { | ||
// fields | ||
protected String deadline; | ||
|
||
// toString | ||
|
||
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. Delete empty lines |
||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + deadline + ")"; | ||
} | ||
|
||
// Constructor | ||
public Deadline(String description, String deadline) { | ||
super(description); | ||
this.deadline = deadline; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.util.Date; | ||
|
||
public class Event extends Task { | ||
// fields | ||
protected String start; | ||
protected String end; | ||
|
||
// toString | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (from: " + start + " to: " + end + ")"; | ||
} | ||
|
||
// Constructor | ||
public Event(String description, String start, String end) { | ||
super(description); | ||
this.start = start; | ||
this.end = end; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.ArrayList; | ||
|
||
public class MyList extends ArrayList<Task> { | ||
public MyList() {} | ||
|
||
public MyList(int initialCapacity) { | ||
super(initialCapacity); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuffer rt = new StringBuffer(); | ||
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. name should be clearer for the reader |
||
for (int i = 0; i < this.size(); i++) { | ||
rt.append(" " + (i+1) + ". " + this.get(i).toString() + "\n"); | ||
} | ||
return rt.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
public class Task { | ||
// fields | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
//Methods | ||
public String getStatusIcon() { | ||
return (isDone ? "[V] " : "[ ] "); // mark done task with V | ||
} | ||
|
||
public boolean mark(int id) { | ||
if (id == 0) { /* to mark unmarked task */ | ||
if (isDone == false) { | ||
isDone = true; | ||
return true; | ||
} else { /* if the task is already marked */ | ||
return false; | ||
} | ||
} else { /* to unmark marked task */ | ||
if (isDone == true) { | ||
isDone = false; | ||
return true; | ||
} else { /* if the task is already unmarked */ | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
// toString | ||
@Override | ||
public String toString() { | ||
return getStatusIcon() + this.description; | ||
} | ||
|
||
// Constructor | ||
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. Place constructor on top |
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class ToDo extends Task { | ||
|
||
// Methods | ||
|
||
|
||
// toString | ||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
|
||
// Constructor | ||
public ToDo(String description) { | ||
super(description); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,54 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Dan: | ||
我是小丹! | ||
有什么可以要帮忙可以跟我说! | ||
|
||
Dan: | ||
新任务: | ||
[T][ ] borrow book! | ||
现在有1项任务哦! | ||
|
||
Dan: | ||
新任务: | ||
[D][ ] return book (by: sunday)! | ||
现在有2项任务哦! | ||
|
||
Dan: | ||
新任务: | ||
[E][ ] project meeting (from: mon 2pm to: 4pm)! | ||
现在有3项任务哦! | ||
|
||
Dan: | ||
你还有些要做的事情呢 我看看有什么吧! | ||
1. [T][ ] borrow book | ||
2. [D][ ] return book (by: sunday) | ||
3. [E][ ] project meeting (from: mon 2pm to: 4pm) | ||
|
||
Dan: | ||
哟 做完啦?帮你标记好了! | ||
[T][V] borrow book | ||
|
||
Dan: | ||
哟 做完啦?帮你标记好了! | ||
[E][V] project meeting (from: mon 2pm to: 4pm) | ||
|
||
Dan: | ||
啊?没做完啊 是不小心手滑了么? | ||
[E][ ] project meeting (from: mon 2pm to: 4pm) | ||
|
||
Dan: | ||
这个没标记过哦! | ||
|
||
Dan: | ||
你还有些要做的事情呢 我看看有什么吧! | ||
1. [T][V] borrow book | ||
2. [D][ ] return book (by: sunday) | ||
3. [E][ ] project meeting (from: mon 2pm to: 4pm) | ||
|
||
Dan: | ||
新任务: | ||
[D][ ] do homework (by: no idea :-p)! | ||
现在有4项任务哦! | ||
|
||
Dan: | ||
拜拜啦!下次见! |
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 job on setting your ToDos as enums!