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

[nihalzp] iP #61

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
da9144b
Rename bot and implement basic greet, exit
nihalzp Aug 27, 2023
75be7ce
Echo the user given command, exit when "bye"
nihalzp Sep 4, 2023
afc511c
Add indentation to responses
nihalzp Sep 4, 2023
332b3f4
Add Python ASCII art
nihalzp Sep 4, 2023
1ebb2bf
Add Python emoji before response
nihalzp Sep 4, 2023
111d8a1
Store commands and display if requested
nihalzp Sep 4, 2023
0093f07
Add task class
nihalzp Sep 4, 2023
8f17b24
Allow mark and unmark of tasks
nihalzp Sep 4, 2023
4cf5d1e
Rename taskList to tasks
nihalzp Sep 4, 2023
7e8e63a
Format and change var names to match Java standards
nihalzp Sep 4, 2023
875d4bb
Add Todo class
nihalzp Sep 6, 2023
dca8d87
Add toString method to task class
nihalzp Sep 14, 2023
bbb2a75
Implement Todo class
nihalzp Sep 14, 2023
a08b038
Implement Deadline class
nihalzp Sep 14, 2023
d0b678e
Implement Deadline class toString method
nihalzp Sep 14, 2023
ec7a82d
Implement Event class
nihalzp Sep 14, 2023
0591c0f
Integrate Todo, Deadline, Event class into chatbot
nihalzp Sep 14, 2023
846bfbf
Remove trailing spaces from Ascii art
nihalzp Sep 14, 2023
dd17203
Add input and expected behaviour of the bot
nihalzp Sep 14, 2023
16606ac
Use all capitals for constant variables
nihalzp Sep 14, 2023
2847381
Change method name to getDone
nihalzp Sep 14, 2023
2ee7cc7
Use constant variables for command names
nihalzp Sep 14, 2023
edcb499
Use newlines to keep coherent blocks together
nihalzp Sep 14, 2023
8235ebc
Add some comments
nihalzp Sep 14, 2023
16258c4
Make Task class abstract
nihalzp Sep 14, 2023
54707ec
Catch exceptions and respond for unexpected input
nihalzp Sep 14, 2023
c60023a
Fix typo in Duke
nihalzp Sep 14, 2023
652ef28
Update input.txt and EXPECTED.TXT
nihalzp Sep 14, 2023
0a328b0
Merging branch-Level-5 into master
nihalzp Sep 14, 2023
a45995b
Rename Duke to Python
nihalzp Sep 18, 2023
a35adec
Organize files into packages
nihalzp Sep 18, 2023
6ce1ada
Update the path in runtest.sh
nihalzp Sep 18, 2023
000bb2e
Merge branch-A-Packages into master
nihalzp Sep 18, 2023
96f5be8
Use String.repeat instead of Arrays.fill
nihalzp Sep 18, 2023
938cdb0
Change method name from getDone() to isDone()
nihalzp Sep 18, 2023
085f7ec
Use Em Dash for horizontal line
nihalzp Sep 18, 2023
cabb00d
Fix path in runtest.sh
nihalzp Sep 18, 2023
8dd6c03
Add support for deleting tasks
nihalzp Sep 18, 2023
0960bfb
Add tests for delete feature
nihalzp Sep 18, 2023
1d7a30b
Implement task details format method for file saving
nihalzp Sep 18, 2023
4ea6ed5
Save tasks after each change to task lists
nihalzp Sep 18, 2023
3c1dc3c
Use type icon constant variable
nihalzp Sep 18, 2023
9141ff6
Add support for loading tasks from file
nihalzp Sep 18, 2023
d6ebb8f
Merge branch-Level-6 into master
nihalzp Sep 18, 2023
efa847a
Merge branch-Level-7 into master
nihalzp Sep 18, 2023
6dbf985
Save tasks to file after delete command
nihalzp Sep 18, 2023
5d81533
Ignore data folder
nihalzp Sep 18, 2023
1e4f784
Use lower case for directory names
nihalzp Oct 5, 2023
e6fb515
Update text-ui-test input and expected text
nihalzp Oct 5, 2023
19bf31a
Add Command class
nihalzp Oct 6, 2023
d34035c
Add Message class
nihalzp Oct 6, 2023
e13479b
Add Parser class
nihalzp Oct 6, 2023
e995cc5
Add Exception class
nihalzp Oct 6, 2023
7bbab3b
Add TaskList class
nihalzp Oct 6, 2023
4a3c6b7
Add Ui class
nihalzp Oct 6, 2023
c84f7dc
Refactor Python.java for more oop
nihalzp Oct 6, 2023
dd0cf10
Update text-ui-testing
nihalzp Oct 6, 2023
ae0c242
Add support for finding tasks
nihalzp Oct 6, 2023
dd55af9
Add manifest.mf
nihalzp Oct 6, 2023
cf0307f
Merge pull request #1 from nihalzp/branch-Level-9
nihalzp Oct 6, 2023
1dab8c7
Add JavaDoc comments
nihalzp Oct 6, 2023
85589ff
Merge pull request #2 from nihalzp/branch-A-JavaDoc
nihalzp Oct 6, 2023
f61a1b9
Add user guide
nihalzp Oct 6, 2023
4d7bdfb
Reorder and fix formatting
nihalzp Oct 6, 2023
3218369
Do not print task count at start
nihalzp Oct 6, 2023
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
22 changes: 22 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Deadline extends Task {
protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String getTypeIcon() {
return "[D]";
}

public String getBy() {
return by;
}

@Override
public String toString() {
return super.toString() + " (by: " + getBy() + ")";
}
}
210 changes: 204 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,208 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Duke {
final private static String BOT_NAME = "Python";
final private static String PYTHON_ASCII_ART =
"\t ____ _ _\n" +
"\t| _ \\ _ _| |_| |__ ___ _ __\n" +
"\t| |_) | | | | __| _ \\ / _ \\| _ \\\n" +
"\t| __/| |_| | |_| | | | (_) | | | |\n" +
"\t|_| \\__, |\\__|_| |_|\\___/|_| |_|\n" +
"\t |___/";
final private static String PYTHON_EMOJI = "\uD83D\uDC0D";

final static private List<Task> tasks = new ArrayList<>();

final private static Scanner in = new Scanner(System.in);

public static final String COMMAND_BYE = "bye";
public static final String COMMAND_LIST = "list";
public static final String COMMAND_MARK = "mark";
public static final String COMMAND_UNMARK = "unmark";
public static final String COMMAND_TODO = "todo";
public static final String COMMAND_DEADLINE = "deadline";
public static final String COMMAND_EVENT = "event";
nihalzp marked this conversation as resolved.
Show resolved Hide resolved

final private static int HORIZONTAL_LINE_LENGTH = 80;
private static void printHorizontalLine() {
char[] horizontalLine = new char[HORIZONTAL_LINE_LENGTH];
Arrays.fill(horizontalLine, '—');
nihalzp marked this conversation as resolved.
Show resolved Hide resolved
System.out.println("\t" + new String(horizontalLine));
}

public static void main(String[] args) {
nihalzp marked this conversation as resolved.
Show resolved Hide resolved
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println(PYTHON_ASCII_ART);
printHorizontalLine();
System.out.printf("\t%s: Hello! I am a short Java Bot %s!\n", PYTHON_EMOJI, BOT_NAME);
System.out.printf("\t%s: What can I do for you?\n", PYTHON_EMOJI);
printHorizontalLine();

String inputLine;
do {
inputLine = in.nextLine();

// Trim extra whitespace characters between words while splitting
String inputCommand = inputLine.split("\\s+")[0];
printHorizontalLine();

switch (inputCommand) {
case COMMAND_BYE:
System.out.printf("\t%s: Bye. See you again when you run the program again!\n", PYTHON_EMOJI);
break;
nihalzp marked this conversation as resolved.
Show resolved Hide resolved
case COMMAND_LIST:
System.out.printf("\t%s: You have %d tasks to do!\n", PYTHON_EMOJI, tasks.size());
for (int taskNo = 1; taskNo <= tasks.size(); taskNo++) {
System.out.printf("\t\t\t%d. %s\n", taskNo, tasks.get(taskNo - 1));
}
break;
case COMMAND_MARK: {
int taskNo;
try {
taskNo = Integer.parseInt(inputLine.split(" ")[1]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_MARK + " command must be followed by an integer (task" +
" id)!");
break;
}

// Handle unintended usage
if (taskNo > tasks.size()) {
System.out.printf("\t%s: Are you from the future?\n", PYTHON_EMOJI);
break;
}
if (tasks.get(taskNo - 1).getDone()) {
System.out.printf("\t%s: Are you from the past?\n", PYTHON_EMOJI);
System.out.printf("\t\tTask: %s\n \t\t is already done!!!\n",
tasks.get(taskNo - 1));
break;
}

tasks.get(taskNo - 1).setDone(true);

System.out.printf("\t%s: Good job completing the task!\n", PYTHON_EMOJI);
System.out.printf("\t\t\t %s\n", tasks.get(taskNo - 1));
break;
}
case COMMAND_UNMARK: {
int taskNo;
try {
taskNo = Integer.parseInt(inputLine.split(" ")[1]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_UNMARK + " command must be followed by an integer (task" +
" id).");
break;
}

// Handle unintended usage
if (taskNo > tasks.size()) {
System.out.printf("\t%s: Are you from the future?\n", PYTHON_EMOJI);
break;
}
if (!tasks.get(taskNo - 1).getDone()) {
System.out.printf("\t%s: Alas! Only the completed tasks can be unmarked!\n", PYTHON_EMOJI);
System.out.printf("\t\tTask: %s\n \t\tis already sitting idle. Get started...!!!\n",
tasks.get(taskNo - 1));
break;
}

tasks.get(taskNo - 1).setDone(false);

System.out.printf("\t%s: Its okay! To err is human! Unmarked!\n", PYTHON_EMOJI);
System.out.printf("\t\t\t %s\n", tasks.get(taskNo - 1));
break;
}
case COMMAND_TODO: {
String todoDescription;
try {
todoDescription = inputLine.split(" ", 2)[1];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_TODO + " command must be followed by a task " +
"description!");
break;
}

System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "New Todo! You have added this todo:");

Todo todo = new Todo(todoDescription);
tasks.add(todo);

System.out.printf("\t\t\t %s\n", todo);
System.out.printf("\t\tYou have %d tasks in total!\n", tasks.size());
break;
}
case COMMAND_DEADLINE: {
String deadlineDetails, deadlineDescription, deadlineBy;
try {
deadlineDetails = inputLine.split(" ", 2)[1];
deadlineDescription = deadlineDetails.split(" /by ")[0];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_DEADLINE + " command must be followed by a task " +
"description!");
break;
}
try {
deadlineBy = deadlineDetails.split(" /by ")[1];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_DEADLINE + " command must have /by clause followed by " +
"time its due!");
break;
}

System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "New Deadline! You have added this deadline:");

Deadline deadline = new Deadline(deadlineDescription, deadlineBy);
tasks.add(deadline);

System.out.printf("\t\t\t %s\n", deadline);
System.out.printf("\t\tYou have %d tasks in total!\n", tasks.size());
break;
}
case COMMAND_EVENT: {
String eventDetails, eventDescription, eventFrom, eventTo;
try {
eventDetails = inputLine.split(" ", 2)[1];
eventDescription = eventDetails.split("\\s+/from\\s+|\\s+/to\\s+", 3)[0];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_EVENT + " command must be followed by a task " +
"description!");
break;
}
try {
eventFrom = eventDetails.split("\\s+/from\\s+|\\s+/to\\s+", 3)[1];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_EVENT + " command must have /from clause followed by " +
"time it starts!");
break;
}
try {
eventTo = eventDetails.split("\\s+/from\\s+|\\s+/to\\s+", 3)[2];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t" + COMMAND_EVENT + " command must have /to clause followed by " +
"time it ends!");
break;
}

System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "New Event! You have added this event:");

Event event = new Event(eventDescription, eventFrom, eventTo);
tasks.add(event);

System.out.printf("\t\t\t %s\n", event);
System.out.printf("\t\tYou have %d tasks in total!\n", tasks.size());
break;
}
default:
if (inputLine.isEmpty()) {
System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "Nothing for me?");
break;
}
System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "I cannot understand the command!");
break;
}
printHorizontalLine();
} while (!inputLine.equals(COMMAND_BYE));
}
}
26 changes: 26 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Event extends Task {
protected String from, to;

public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}

public String getTypeIcon() {
return "[E]";
}

public String getFrom() {
return from;
}

public String getTo() {
return to;
}

@Override
public String toString() {
return super.toString() + " (from: " + getFrom() + " to: " + getTo() + ")";
}
}
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 abstract class Task {
nihalzp marked this conversation as resolved.
Show resolved Hide resolved
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 abstract String getTypeIcon();

public String getDescription() {
return description;
}

public boolean getDone() {
nihalzp marked this conversation as resolved.
Show resolved Hide resolved
return isDone;
}

public void setDone(boolean done) {
isDone = done;
}

@Override
public String toString() {
return getTypeIcon() + getStatusIcon() + " " + getDescription();
}
}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public String getTypeIcon() {
return "[T]";
}
}
Loading