Skip to content
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

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e3bb1f1
Duke.java: change chatbot name to Pythia
Ijaaz01 Jan 25, 2024
550f897
Duke.java: Increment level 1
Ijaaz01 Feb 1, 2024
6c2a44c
Duke.java: increment level 2
Ijaaz01 Feb 1, 2024
c9bf241
Duke.java: increment level 3
Ijaaz01 Feb 1, 2024
93f250d
Level 4: add todo, deadline, event functionality
Ijaaz01 Feb 9, 2024
2ff2c78
Add PythiaException class
Ijaaz01 Feb 15, 2024
617ba63
Add throws and catches to main loop
Ijaaz01 Feb 15, 2024
a9162e1
Merge branch 'branch-Level-5'
Ijaaz01 Feb 15, 2024
99083da
Add package duke
Ijaaz01 Feb 21, 2024
36b6f21
Merge branch 'branch-A-Packages'
Ijaaz01 Feb 21, 2024
b18d968
Add delete functionality
Ijaaz01 Feb 21, 2024
11a53c8
Add save functionality, jar file
Ijaaz01 Feb 21, 2024
9ed796b
Merge branch 'branch-Level-6'
Ijaaz01 Feb 21, 2024
8dd0afc
Bug fix, add filewriter.close
Ijaaz01 Feb 21, 2024
22bef9f
Merge branch 'branch-Level-7'
Ijaaz01 Feb 21, 2024
c2444c9
Fix format for event printing, save list automatically
Ijaaz01 Feb 22, 2024
a608d2a
Bug fixes
Ijaaz01 Feb 23, 2024
0639287
Refactor code, add command class, bug fix savedlist retrieval
Ijaaz01 Feb 23, 2024
bfffd2b
Add find functionality
Ijaaz01 Mar 6, 2024
f1019fd
Merge pull request #1 from Ijaaz01/branch-Level-9
Ijaaz01 Mar 6, 2024
8c70edb
Add UI, TaskList, unparsedTaskList and Storage classes
Ijaaz01 Mar 6, 2024
8fbb360
Add JavaDoc for UI, Parser and Command classes
Ijaaz01 Mar 7, 2024
f35f2ba
Merge pull request #2 from Ijaaz01/branch-A-JavaDoc
Ijaaz01 Mar 7, 2024
1f2ea47
Add JavaDoc headers for Duke, Storage, TaskList and UnparsedTaskList
Ijaaz01 Mar 7, 2024
1347803
Edit made to README.md file
Ijaaz01 Mar 7, 2024
f5e750d
Final touch ups to README file
Ijaaz01 Mar 7, 2024
2b44fe6
Fix formatting error in README file
Ijaaz01 Mar 7, 2024
def90c3
Add help command and angry sprite
Ijaaz01 Mar 8, 2024
12225f9
Add help command to README file
Ijaaz01 Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {

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.

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 + ")";
}
}
58 changes: 52 additions & 6 deletions src/main/java/Duke.java
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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert a line break after your import statements.

Choose a reason for hiding this comment

The 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 = "----------------------------------------------------------";

Choose a reason for hiding this comment

The 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")) {
Copy link

Choose a reason for hiding this comment

The 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);
}
}
17 changes: 17 additions & 0 deletions src/main/java/Event.java
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]";

Choose a reason for hiding this comment

The 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 + ")";
}
}
27 changes: 27 additions & 0 deletions src/main/java/MoodSprite.java
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;
}
}
45 changes: 45 additions & 0 deletions src/main/java/Parser.java
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"));
}
}
3 changes: 3 additions & 0 deletions src/main/java/PythiaException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class PythiaException extends Exception{

}
32 changes: 32 additions & 0 deletions src/main/java/Task.java
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() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming your setter methods. Perhaps you could change it to setDoneAsTrue() or something?

isDone = false;
}

public void doneIsTrue() {
isDone = true;
}

public String getDoneStatus() {
return (isDone ? "[X]" : "[ ]");
}

public String getDescription() {
return description;
}

Choose a reason for hiding this comment

The 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;
}

}
7 changes: 7 additions & 0 deletions src/main/java/Todo.java
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]";
}
}