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

Branch level 9 #1

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: python.Python

1 change: 1 addition & 0 deletions src/main/java/python/parser/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Command {
public static final String COMMAND_TODO = "todo";
public static final String COMMAND_DEADLINE = "deadline";
public static final String COMMAND_EVENT = "event";
public static final String COMMAND_FIND = "find";

public static boolean isCommandBye(String command) {
return (command.equals(COMMAND_BYE));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/python/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public static int extractTaskNoFromInputLine(String inputLine) {
return Integer.parseInt(inputLine.split(" ")[1]);
}

public static String extractKeywordFromInputLine(String inputLine) {
return inputLine.split(" ")[1];
}

public static String extractTodoDescFromInputLine(String inputLine) {
return inputLine.split(" ", 2)[1];
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/python/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ public static void addTask(Task task) {
tasks.add(task);
}

public static List<Task> findTask(String keyword) {
List<Task> matchedTasks = new ArrayList<>();
for (int taskNo = 0; taskNo < getNumberOfTasks(); taskNo++) {
if (getTask(taskNo).getDescription().contains(keyword)) {
matchedTasks.add(getTask(taskNo));
}
}
return matchedTasks;
}
}
3 changes: 3 additions & 0 deletions src/main/java/python/ui/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Message {
final static String MESSAGE_ASK = "What can I do for you?";
final static String MESSAGE_BYE = "Bye. See you again when you run the program again!";
final static String MESSAGE_INT_AFTER_COMMAND = "Command must be followed by an integer (task id)!";
final static String MESSAGE_KEYWORD_AFTER_COMMAND = "Command must be followed by a keyword!";
final static String MESSAGE_DESC_AFTER_COMMAND = "Command must be followed by a task description!!";
final static String MESSAGE_TIME_AFTER_FROM_CLAUSE =
"Command must have /from clause followed by time it starts!";
Expand All @@ -25,4 +26,6 @@ public class Message {
final static String MESSAGE_NEW_TODO = "New Todo! You have added this todo:";
final static String MESSAGE_NEW_DEADLINE = "New Deadline! You have added this deadline:";
final static String MESSAGE_NEW_EVENT = "New Event! You have added this event:";
final static String MESSAGE_NO_MATCH = "No matching tasks found!";
final static String MESSAGE_MATCHES_FOUND = "Here are the matching tasks:";
}
30 changes: 26 additions & 4 deletions src/main/java/python/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import python.task.Event;
import python.task.TaskList;
import python.task.Todo;
import python.task.Task;

import java.util.List;
import java.util.Scanner;

public class Ui {
Expand Down Expand Up @@ -51,9 +53,9 @@ public void displayTaskCount() {
addEmojiAndPrint("You have " + TaskList.getNumberOfTasks() + " tasks!");
}

public void displayTasks() {
for (int taskNo = 0; taskNo < TaskList.getNumberOfTasks(); taskNo++) {
System.out.printf("\t\t\t%d. %s\n", taskNo + 1, TaskList.getTask(taskNo));
public void displayTasks(List<Task> tasks) {
for (int taskNo = 0; taskNo < tasks.size(); taskNo++) {
System.out.printf("\t\t\t%d. %s\n", taskNo + 1, tasks.get(taskNo));
}
}

Expand All @@ -75,7 +77,7 @@ private void handleByeCommand() {

private void handleListCommand() {
displayTaskCount();
displayTasks();
displayTasks(TaskList.getTasks());
}

private void handleMarkCommand() throws PythonException {
Expand Down Expand Up @@ -224,6 +226,23 @@ private void handleEventCommand() throws PythonException {
displayTaskCount();
}

private void handleFindCommand() throws PythonException {
String keyword;
try {
keyword = Parser.extractKeywordFromInputLine(inputLine);
} catch (ArrayIndexOutOfBoundsException e) {
throw new PythonException(Message.MESSAGE_KEYWORD_AFTER_COMMAND);
}

List<Task> matchedTasks = TaskList.findTask(keyword);

if (matchedTasks.isEmpty()) addEmojiAndPrint(Message.MESSAGE_NO_MATCH);
else {
addEmojiAndPrint(Message.MESSAGE_MATCHES_FOUND);
displayTasks(matchedTasks);
}
}

private void handleUnknownCommand() throws PythonException {
if (inputLine.isEmpty()) {
addEmojiAndPrint(Message.MESSAGE_EMPTY_COMMAND_JOKE);
Expand Down Expand Up @@ -260,6 +279,9 @@ public void executeLine() throws PythonException {
case Command.COMMAND_EVENT:
handleEventCommand();
break;
case Command.COMMAND_FIND:
handleFindCommand();
break;
default:
handleUnknownCommand();
break;
Expand Down
9 changes: 9 additions & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@
🐍: [E][ ] OOP Lecture (from: 12pm to: 2pm)
🐍: You have 8 tasks!
————————————————————————————————————————————————————————————————————————————————
🐍: Here are the matching tasks:
1. [T][ ] borrow book
2. [D][X] return book (by: Sunday)
3. [D][ ] return book (by: 2 June)
————————————————————————————————————————————————————————————————————————————————
Error: Command must be followed by a keyword!
————————————————————————————————————————————————————————————————————————————————
🐍: No matching tasks found!
————————————————————————————————————————————————————————————————————————————————
🐍: You have 8 tasks!
1. [T][ ] borrow book
2. [T][X] borrow cycle
Expand Down
3 changes: 3 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ event OOP Lecture
event OOP Lecture /from 12pm
event OOP Lecture /from /to 2pm
event OOP Lecture /from 12pm /to 2pm
find book
find
find exam
list
unmark 3
unmark 4
Expand Down