Skip to content

Commit

Permalink
Level-9: Find
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Jan 28, 2020
1 parent 52f5106 commit c2a3d8a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void main(String[] args) {
isListening = false;

} else if (action.equalsIgnoreCase("list")) {
tasks.printInputs();
tasks.printTasks();

} else if (action.equalsIgnoreCase("done")) {
String context = command_broken[1];
Expand All @@ -59,10 +59,20 @@ public static void main(String[] args) {
tasks.addInput(new ToDos(command_broken[1], false));

} else if (action.equalsIgnoreCase(("event"))) {
System.out.println("Got it, I've added this task");
System.out.println("UNDERSTOOD. CHANCE OF FAILURE: 0%");
String context = command_broken[1];
String[] context_broken = context.split(" /at ", 2);
tasks.addInput(new Events(context_broken[0], false,context_broken[1]));
tasks.addInput(new Events(context_broken[0], false, context_broken[1]));

} else if (action.equalsIgnoreCase("find")) {
System.out.println("OPERATION SUCCESSFULL");
int count = 1;
for (Task t: tasks.getAllTasks()) {
if (t.containsSubstring(command_broken[1])) {
System.out.println(count + "." + t);
count++;
}
}

} else {
throw new DukeException("Ooops! I'm sorry, i don't know what it means");
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public Task(String description, Boolean isDone) {
this.isDone = isDone;
}

public static Task taskList(String[] taskParams) {
public static Task createStartingTask(String[] taskParams) {
String type = taskParams[0];
boolean isDone = taskParams[1].equals("true");
String description = taskParams[2];
Expand All @@ -27,6 +27,10 @@ public static Task taskList(String[] taskParams) {
}
}

public boolean containsSubstring(String search) {
return description.contains(search);
}

public boolean isDone() {
return isDone;
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/UserText.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ public void readText() {
String s;
while ((s = bufferedreader.readLine()) != null) {
String[] taskParams = s.split("/divide");
/*for (String ss : taskParams) {
System.out.println(ss);
}*/
Task task = Task.taskList(taskParams);
Task task = Task.createStartingTask(taskParams);
allTasks.add(task);
}
} catch (IOException ioException) {

}
}

public void printInputs() {
public void printTasks() {
int count = 1;
System.out.println("Here is your list");
for (Task s : allTasks) {
Expand All @@ -70,6 +67,10 @@ public Task getTask(int n) {
return this.allTasks.get(n-1);
}

public List<Task> getAllTasks() {
return this.allTasks;
}

public void markDone(int taskNo) {
allTasks.get(taskNo - 1).markAsDone();
System.out.println("Nice! I marked this task as done");
Expand Down

0 comments on commit c2a3d8a

Please sign in to comment.