-
Notifications
You must be signed in to change notification settings - Fork 187
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
Duke ip update #175
base: master
Are you sure you want to change the base?
Duke ip update #175
Changes from 8 commits
e3bb1f1
550f897
6c2a44c
c9bf241
93f250d
2ff2c78
617ba63
a9162e1
99083da
36b6f21
b18d968
11a53c8
9ed796b
8dd0afc
22bef9f
c2444c9
a608d2a
0639287
bfffd2b
f1019fd
8c70edb
8fbb360
f35f2ba
1f2ea47
1347803
f5e750d
2b44fe6
def90c3
12225f9
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 by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by.replaceFirst("by", "by:"); | ||
this.taskId = "[D]"; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return taskId + this.getDoneStatus() + " " + description + " (" + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,56 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
public class Duke { | ||
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. Insert a line break after your import statements. 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. not compulsory but would be good if you can rename the class according to the name of your chatbot |
||
private static MoodSprite mood = new MoodSprite(); | ||
private static List<Task> list = new ArrayList<>(2); | ||
private static Parser parser = new Parser(); | ||
private static final String 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 work with the usage of Access Modifiers. |
||
public static void printList(List<Task> list) { | ||
for (int i = 0; i < list.size(); i++) { | ||
System.out.println((i+1)+"."+list.get(i)); | ||
} | ||
} | ||
|
||
public static void mainLoop(String input) throws PythiaException { | ||
if (input.equalsIgnoreCase("list")) { | ||
printList(list); | ||
} | ||
else if (parser.isTaskCommand(input)) { | ||
try { | ||
list.add(parser.addTask(input)); | ||
System.out.println("added: " + list.get(list.size() - 1)); | ||
} catch (PythiaException pe) { | ||
System.out.println("Please provide a proper input"); | ||
} | ||
} | ||
else if (input.contains("unmark ")) { | ||
String[] splitInput = input.split(" "); | ||
list.get(Integer.parseInt(splitInput[1])-1).doneIsFalse(); | ||
System.out.println("Unmarked "+ Integer.parseInt(splitInput[1])); | ||
} | ||
else if (input.contains("mark ")) { | ||
String[] splitInput = input.split(" "); | ||
list.get(Integer.parseInt(splitInput[1])-1).doneIsTrue(); | ||
System.out.println("Marked "+ Integer.parseInt(splitInput[1])); | ||
} | ||
else { | ||
throw new PythiaException(); | ||
} | ||
System.out.println(lineBreak); | ||
} | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
String input = "Start"; | ||
Scanner in = new Scanner(System.in); | ||
System.out.println(mood.getIdle() + "Hello, Im Pythia, how may I help you today?\n"+lineBreak); | ||
while (!input.equals("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. Add a line break before your while loop. |
||
input = in.nextLine(); | ||
try { | ||
mainLoop(input); | ||
} catch (PythiaException pe) { | ||
System.out.println("Not a valid command"); | ||
} | ||
} | ||
System.out.println(mood.getHappy()+"Happy to help, have a great day.\n"+lineBreak); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
public class Event extends Task{ | ||
protected String from; | ||
protected String to; | ||
|
||
public Event(String description, String from, String to) { | ||
super(description); | ||
this.from = from.replaceFirst("from", "from:"); | ||
this.to = to.replaceFirst("to", "to:"); | ||
this.taskId = "[E]"; | ||
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 the usage of Magic literals. |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return taskId + this.getDoneStatus() + " " + description + " (" + from + " " + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public class MoodSprite { | ||
private static final String HAPPY = " ███ \n" | ||
+ " ███████ \n" | ||
+ " ████ ████ \n" | ||
+ " ███ ███ \n" | ||
+ " ██ ██ \n" | ||
+ " ██ ██\n" | ||
+ " ███ ███ \n" | ||
+ " ███████████████ \n\n"; | ||
|
||
private static final String IDLE = " █████████████ \n" | ||
+ " ██ ██ \n" | ||
+ " ██ █████ ██ \n" | ||
+ " ██ █████ ██ \n" | ||
+ " ██ ██ \n" | ||
+ " █████████████ \n" | ||
+ " ██ ██\n" | ||
+ " ██████████████████ \n\n"; | ||
|
||
public String getHappy() { | ||
return HAPPY; | ||
} | ||
|
||
public String getIdle() { | ||
return IDLE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
public class Parser { | ||
public String[] splitTaskTrimmer(String[] splitTask) { | ||
for (int i = 0; i < splitTask.length; i++) { | ||
splitTask[i] = splitTask[i].trim(); | ||
} | ||
return splitTask; | ||
} | ||
public String[] parseDeadline(String task) { | ||
task = task.replaceFirst("deadline", ""); | ||
return splitTaskTrimmer(task.split("/")); | ||
} | ||
|
||
public String[] parseEvent(String task) { | ||
task = task.replaceFirst("event", ""); | ||
return splitTaskTrimmer((task.split("/"))); | ||
} | ||
public Task addTask(String task) throws PythiaException{ | ||
String[] parsedTask; | ||
if (task.contains("todo ")) { | ||
task = task.replaceFirst("todo", ""); | ||
if (task.isBlank()) { | ||
throw new PythiaException(); | ||
} | ||
return new Todo(task); | ||
} else if (task.contains("deadline ")) { | ||
parsedTask = parseDeadline(task); | ||
if (parsedTask.length < 2) { | ||
throw new PythiaException(); | ||
} | ||
return new Deadline(parsedTask[0], parsedTask[1]); | ||
} else if (task.contains("event ")){ | ||
parsedTask = parseEvent(task); | ||
if (parsedTask.length < 3) { | ||
throw new PythiaException(); | ||
} | ||
return new Event(parsedTask[0], parsedTask[1], parsedTask[2]); | ||
} else { | ||
throw new PythiaException(); | ||
} | ||
} | ||
|
||
public boolean isTaskCommand(String task) { | ||
return (task.contains("todo") | task.contains("deadline") | task.contains("event")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public class PythiaException extends Exception{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
protected String taskId; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
isDone = false; | ||
} | ||
|
||
public void doneIsFalse() { | ||
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 renaming your setter methods. Perhaps you could change it to |
||
isDone = false; | ||
} | ||
|
||
public void doneIsTrue() { | ||
isDone = true; | ||
} | ||
|
||
public String getDoneStatus() { | ||
return (isDone ? "[X]" : "[ ]"); | ||
} | ||
|
||
public String getDescription() { | ||
return 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. additional line here that can be removed |
||
@Override | ||
public String toString() { | ||
return taskId + this.getDoneStatus() + " " + description; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Todo extends Task{ | ||
|
||
public Todo (String description) { | ||
super(description); | ||
this.taskId = "[T]"; | ||
} | ||
} |
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.
Comments are missing. Good to have them for better readability.