-
Notifications
You must be signed in to change notification settings - Fork 193
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
[Kairos Koh] iP #189
base: master
Are you sure you want to change the base?
[Kairos Koh] iP #189
Changes from 11 commits
98e53ab
e0d5c4d
ca6b0fe
13d9a37
9dcbc95
c3d9af5
72f7593
1e289bf
7b50777
af71eb3
6c57ecf
e8d8f41
11315c6
7c26728
3cf54db
15d6adf
57d09ac
eac25f9
c41f3af
b8098ba
dfb01a0
972d782
663b585
e41e1f4
bc60895
b2b063c
253abe3
4780c7e
411c77a
493ebcc
7db017f
2ac4093
0da697a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package duke; | ||
|
||
public class Deadline extends Task{ | ||
|
||
protected final static char LETTER = 'D'; | ||
protected String date; | ||
|
||
public Deadline(String description, String date) { | ||
super(description); | ||
this.date = date; | ||
} | ||
|
||
public String toString() { | ||
return description; | ||
} | ||
|
||
public char getLetter() { | ||
return LETTER; | ||
} | ||
|
||
public String getDate() { | ||
return "(by: " + date + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package duke; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
public static void main(String[] args) { | ||
|
||
// Welcome Message | ||
printWelcomeMessage(); | ||
|
||
// Active Chat | ||
activeChat(); | ||
|
||
// Goodbye Message | ||
printGoodbyeMessage(); | ||
} | ||
|
||
private static void activeChat() { | ||
boolean isBye = false; | ||
String input; | ||
Scanner in = new Scanner(System.in); | ||
int counter = 0; | ||
Task[] list = new Task[100]; | ||
|
||
while(!isBye){ | ||
//store input | ||
input = in.nextLine(); | ||
//process input | ||
if (input.equals("bye")){ //check if bye | ||
isBye = true; | ||
} else if (input.equals("list")) { //check if list | ||
processList(counter, list); | ||
} else if (input.contains("done") ) { //check if done | ||
processDone(input, list); | ||
} else { | ||
try { | ||
counter = processTasks(input, counter, list); //process tasks | ||
} catch ( IllegalTaskException e ) { | ||
System.out.println("Please include /by for deadline and /at for event"); | ||
} | ||
} | ||
} | ||
} | ||
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. Consider implementing a Parser class to parse user inputs instead of putting everything in main/Duke |
||
|
||
private static void processList(int counter, Task[] list) { | ||
if (list[0] != null){ | ||
printListMessage(counter, list); | ||
} else { | ||
printListButEmptyMessage(); | ||
} | ||
} | ||
|
||
private static void processDone(String input, Task[] list) { | ||
int donePos = input.indexOf("done"); | ||
if (list[0] != null) { | ||
if (input.length() < donePos + 5) { | ||
printDoneButNotSpecificMessage(); //when input contains done but no number | ||
} else { | ||
processValidDone(input, list, donePos); //when input contains done and specified number | ||
} | ||
} else { | ||
printDoneButEmptyMessage(); //when input contains done but list is empty | ||
} | ||
} | ||
|
||
private static void processValidDone(String input, Task[] list, int donePos) { | ||
String itemNumDone = input.substring(donePos + 5, donePos + 6); | ||
int itemNum = Integer.parseInt(itemNumDone); | ||
list[itemNum - 1].setDone(); | ||
printDoneMessage(list, itemNum); | ||
} | ||
|
||
private static int processTasks(String input, int counter, Task[] list) throws IllegalTaskException{ | ||
if ( ( input.contains("deadline") || input.contains("event") ) && !input.contains("/")){ | ||
throw new IllegalTaskException(); | ||
} | ||
if (input.contains("todo")) { | ||
String description = input.substring(5); | ||
ToDo newTask = new ToDo(description); | ||
list[counter] = newTask; | ||
counter += 1; | ||
printAddedTaskMessage(newTask, counter); | ||
} else if (input.contains("deadline")) { | ||
int donePos = input.indexOf("/"); //finds pos of '/' | ||
String description = input.substring(9,donePos); | ||
if (!input.substring(donePos + 1, donePos + 3).equals("by")) { | ||
throw new IllegalTaskException(); | ||
} | ||
String date = input.substring(donePos + 4); | ||
Deadline newTask = new Deadline(description,date); | ||
list[counter] = newTask; | ||
counter += 1; | ||
printAddedTaskMessage(newTask, counter); | ||
} else if (input.contains("event")) { | ||
int donePos = input.indexOf("/"); //finds pos of '/' | ||
String description = input.substring(6,donePos); | ||
if (!input.substring(donePos + 1, donePos + 3).equals("by")) { | ||
throw new IllegalTaskException(); | ||
} | ||
String date = input.substring(donePos + 4); | ||
Event newTask = new Event(description,date); | ||
list[counter] = newTask; | ||
counter += 1; | ||
printAddedTaskMessage(newTask, counter); | ||
} else { | ||
System.out.println("Please specify tasks: todo, deadline or event"); | ||
System.out.println("Example - type in the following: todo read book"); | ||
} | ||
return counter; | ||
} | ||
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. Consider creating TaskManger class to handle task manipulation as well as storing their data for your task list |
||
|
||
private static void printDoneMessage(Task[] list, int itemNum) { | ||
System.out.println("--------------------"); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println( itemNum + ".[" + list[itemNum - 1].getStatusIcon() + "] " + list[itemNum - 1].getDescription() ); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void printListMessage(int counter, Task[] list) { | ||
System.out.println("--------------------"); | ||
System.out.println("Here are the tasks in your list:"); | ||
for(int i = 0; i < counter; i += 1){ | ||
printListOfTaskSubMessage(list[i], i); | ||
} | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void printListButEmptyMessage() { | ||
System.out.println("--------------------"); | ||
System.out.println("List is empty. Time to get productive!"); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void printDoneButNotSpecificMessage() { | ||
System.out.println("Please specify which task is done."); | ||
} | ||
|
||
private static void printDoneButEmptyMessage() { | ||
System.out.println("--------------------"); | ||
System.out.println("Unable to tick off list."); | ||
System.out.println("List is empty. Time to get productive!"); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void printAddedTaskMessage(Task task, int i) { | ||
System.out.println("--------------------"); | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println("[" + task.getLetter() + "] " | ||
+ "[" + task.getStatusIcon() + "] " | ||
+ task.getDescription() | ||
+ task.getDate() ); | ||
System.out.println("Now you have " + i + " tasks in the list."); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void printListOfTaskSubMessage(Task task, int i) { | ||
System.out.println(i + 1 | ||
+ ".[" + task.getLetter() + "] " | ||
+ "[" + task.getStatusIcon() + "] " | ||
+ task.getDescription() | ||
+ task.getDate() ); | ||
} | ||
|
||
private static void printGoodbyeMessage() { | ||
System.out.println("--------------------"); | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
System.out.println(" "); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void printWelcomeMessage() { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
System.out.println("--------------------"); | ||
System.out.println("Hello! I'm Duke"); | ||
System.out.println("What can I do for you?"); | ||
System.out.println(" "); | ||
System.out.println("--------------------"); | ||
} | ||
} | ||
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. Consider creating a UI class to handle your print statements instead |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package duke; | ||
|
||
public class Event extends Task{ | ||
|
||
protected final static char LETTER = 'E'; | ||
protected String date; | ||
|
||
public Event(String description, String date) { | ||
super(description); | ||
this.date = date; | ||
} | ||
|
||
public String toString() { | ||
return description; | ||
} | ||
|
||
public char getLetter() { | ||
return LETTER; | ||
} | ||
|
||
public String getDate() { | ||
return "(at: " + date + ")"; | ||
} | ||
|
||
|
||
} | ||
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. Consider creating packages for your Event, Todo classes etc. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package duke; | ||
|
||
public class IllegalTaskException extends Exception{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package duke; | ||
|
||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(){ | ||
this.description = ""; | ||
isDone = false; | ||
} | ||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription(){ | ||
return this.description; | ||
} | ||
|
||
public void setDone(){ | ||
this.isDone = true; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public char getLetter() { | ||
return ' '; | ||
} | ||
|
||
public String getDate() { | ||
return " "; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package duke; | ||
|
||
public class ToDo extends Task{ | ||
|
||
protected final static char LETTER = 'T'; | ||
|
||
public ToDo(String description) { | ||
super(description); | ||
} | ||
|
||
public String toString() { | ||
return description; | ||
} | ||
|
||
public char getLetter() { | ||
return LETTER; | ||
} | ||
|
||
public String getDate() { | ||
return ""; | ||
} | ||
|
||
} |
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.
Note if the comments are necessary, else remove them if they are not