-
Notifications
You must be signed in to change notification settings - Fork 78
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
[Jiayan Ben] iP #76
base: master
Are you sure you want to change the base?
[Jiayan Ben] iP #76
Changes from 14 commits
aa5ed3d
28f7f8f
1a006be
f963203
ce21c8c
d6f4537
22f7501
a151504
752b8bf
abd1548
677d91b
6617431
0c932c0
4024b7f
e01ca3e
888d9c5
ec736b8
f87152b
eabd967
73d4714
12e33ab
e49be03
0e0d08a
346d4bf
5908426
8c9a743
73a6403
851801e
156c911
00c05b9
2c00b17
85b7029
efa64fe
da1aa7c
34cd429
b9e9816
30fa3f2
85591e4
8a84838
3a3c454
3ba847c
c268b0b
54da8eb
00f58b5
bef8a97
80570c9
dbc9bc6
aa1cba6
27038e5
4bd199b
fb1402f
3b83a3a
8ced34e
1cb1fbc
abef09a
c47970e
a55d901
076e890
e74a144
89afba9
6554b32
c9771ed
f98e169
05c9b9e
194de5e
a8bd915
88d20d2
d89c626
70f7f2b
6d96bf2
a1d77ec
2313371
52df463
20bc921
c25848c
7e8712d
564d7d8
aa8a38c
dc6e648
303fd3d
dbb5b0b
2a2d9a1
9dd679e
8b13eb1
815481e
5996557
f57a735
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 byDeadline; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.byDeadline = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + this.byDeadline + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,96 @@ | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
public static int taskCount = 0; | ||
private static Task[] list = new Task[100]; | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
printWelcomeMessage(); | ||
Scanner keyboard = new Scanner(System.in); | ||
|
||
while (true) { | ||
String command = keyboard.nextLine(); | ||
String[] commendSplits = command.split(" "); | ||
int spaceIndex, taskNo; | ||
|
||
switch (commendSplits[0]) { | ||
case "bye": | ||
printByeMessage(); | ||
keyboard.close(); | ||
return; | ||
|
||
case "list": | ||
printList(taskCount, list); | ||
break; | ||
|
||
case "mark": | ||
// command format e.g. mark 1 | ||
taskNo = Integer.parseInt(commendSplits[1]); //assume saved in part[1], need further improve | ||
list[taskNo - 1].setDone(taskNo, taskCount, list); | ||
break; | ||
|
||
case "unmark": | ||
taskNo = Integer.parseInt(commendSplits[1]); //assume saved in part[1], need further improve | ||
list[taskNo - 1].setNotDone(taskNo, taskCount, list); | ||
break; | ||
|
||
case "todo": | ||
// command format e.g. todo borrow book | ||
String[] todoSplit = command.split(" ", 2); | ||
list[taskCount] = new Todo(todoSplit[1]); | ||
createTaskSuccessMsg(); | ||
break; | ||
|
||
case "deadline": | ||
// command e.g. deadline return book /by Sunday | ||
String[] ddlSplit = command.split("/"); | ||
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. Avoid using short forms as variable names as it might confuse readers with different backgrounds. |
||
spaceIndex = ddlSplit[0].indexOf(" "); | ||
String ddlTask = ddlSplit[0].substring(spaceIndex + 1).trim(); | ||
list[taskCount] = new Deadline(ddlTask, ddlSplit[1].substring(3)); | ||
createTaskSuccessMsg(); | ||
break; | ||
|
||
case "event": | ||
//command e.g. event project meeting /from Mon 2pm /to 4pm | ||
String[] eventSplit = command.split("/"); | ||
spaceIndex = eventSplit[0].indexOf(" "); | ||
String eventTask = eventSplit[0].substring(spaceIndex + 1).trim(); | ||
String start = eventSplit[1].trim().substring(5); // Remove "/from " prefix | ||
String end = eventSplit[2].trim().substring(3); // Remove "/to " prefix | ||
list[taskCount] = new Event(eventTask, start, end); | ||
createTaskSuccessMsg(); | ||
break; | ||
|
||
default: | ||
System.out.println("Sorry. This is not expected."); | ||
System.out.println("Please type in \"help\" to look for command format"); | ||
} | ||
} | ||
|
||
} | ||
|
||
private static void createTaskSuccessMsg() { | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(list[taskCount]); | ||
taskCount++; | ||
System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
} | ||
|
||
private static void printByeMessage() { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
private static void printWelcomeMessage() { | ||
System.out.println("Hello! I'm Oriento."); | ||
System.out.println("What can I do for you?"); | ||
} | ||
|
||
private static void printList(int count, Task[] list) { | ||
for (int i = 0; i < count; i++) { | ||
//example 1.[T][X] read book | ||
System.out.println((i + 1) + "." + list[i]); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
public class Event extends Task { | ||
protected String start, end; | ||
|
||
public Event(String description, String start, String end) { | ||
super(description); | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
//print example: [E][ ] project meeting (from: Aug 6th 2pm to: 4pm) | ||
return "[E]" + super.toString() + " (from: " + this.start + " to: " + this.end + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 | ||
} | ||
|
||
public void setDone(int taskNo, int taskCount, Task[] list){ | ||
if( (taskNo > taskCount ) || (taskNo <1) ){ | ||
System.out.println("Oops! You don't have any task in this positions."); | ||
}else if(this.isDone){ | ||
System.out.println("You have already completed the task."); | ||
} else{ | ||
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. Spacing of the if else statements does not follow standards. Similar in other areas |
||
this.isDone = true; | ||
System.out.println(" Nice! I've marked this task as done:\n" | ||
+ " [X] " + list[taskNo - 1].description); | ||
} | ||
} | ||
|
||
public void setNotDone(int taskNo, int taskCount, Task[] list){ | ||
if( (taskNo > taskCount ) || (taskNo <1) ){ | ||
System.out.println("Oops! You don't have any task in this position."); | ||
}else if(!this.isDone){ | ||
System.out.println("Oh, you haven't finished this yet."); | ||
} else{ | ||
this.isDone = false; | ||
System.out.println("OK, I've marked this task as not done yet:\n" | ||
+ " [ ] " + list[taskNo - 1].description); | ||
} | ||
} | ||
|
||
@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() ; | ||
} | ||
} | ||
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 use of inheritance in implementation of toString(). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Hello! I'm Oriento. | ||
What can I do for you? | ||
Got it. I've added this task: | ||
[T][ ] read book | ||
Now you have 1 tasks in the list. | ||
Got it. I've added this task: | ||
[T][ ] play piano | ||
Now you have 2 tasks in the list. | ||
Nice! I've marked this task as done: | ||
[X] play piano | ||
Got it. I've added this task: | ||
[D][ ] return book (by: Friday) | ||
Now you have 3 tasks in the list. | ||
Got it. I've added this task: | ||
[E][ ] java lesson (from: Friday 4pm to: 6pm) | ||
Now you have 4 tasks in the list. | ||
Oh, you haven't finished this yet. | ||
1.[T][ ] read book | ||
2.[T][X] play piano | ||
3.[D][ ] return book (by: Friday) | ||
4.[E][ ] java lesson (from: Friday 4pm to: 6pm) | ||
Bye. Hope to see you again soon! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
todo read book | ||
todo play piano | ||
mark 2 | ||
deadline return book /by Friday | ||
event java lesson /from Friday 4pm /to 6pm | ||
unmark 4 | ||
list | ||
bye |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@ECHO OFF | ||
|
||
REM create bin directory if it doesn't exist | ||
if not exist ..\bin mkdir ..\bin | ||
|
||
REM delete output from previous run | ||
del ACTUAL.TXT | ||
|
||
REM compile the code into the bin folder | ||
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java | ||
IF ERRORLEVEL 1 ( | ||
echo ********** BUILD FAILURE ********** | ||
exit /b 1 | ||
) | ||
REM no error here, errorlevel == 0 | ||
|
||
REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT | ||
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT | ||
|
||
REM compare the output to the expected output | ||
FC ACTUAL.TXT EXPECTED.TXT |
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.
Small typo on "commendSplits"