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 find #327

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3eca3f3
Level-0: Greet
Aug 31, 2020
dc6fb15
Level-1: Greet, Echo, Exit
Sep 1, 2020
4879598
Level-2: Add, List
Sep 1, 2020
ae2b8b1
A-Classes: add markAsDone method
Sep 1, 2020
67c6c0c
Level-3: Mark as Done
Sep 1, 2020
3fb5552
Naming: Some variables are named incorrectly and switch and while do …
Sep 1, 2020
833fd24
Level 4. ToDos, Events, Deadlines & A-Inheritance
Sep 1, 2020
fd3f7f5
A-TextUiTesting
Sep 1, 2020
d86b767
A-CodeQuality
Sep 2, 2020
8ad0229
CodeQuality
Sep 8, 2020
3fbb3df
Level-5: Handle Errors
Sep 9, 2020
c1fbffe
Merge branch 'branch-Level-5'
Sep 9, 2020
8e64f22
A-Packages: Organize into Packages & two more exceptions
Sep 9, 2020
b8c114e
add one more exception catching done commands exceeding total index l…
Sep 15, 2020
9baa0af
A-Collections
Sep 15, 2020
4c43172
A-Collections
Sep 15, 2020
e5a1fba
Level 6. Delete
Sep 15, 2020
520a406
Level-7: Save
Sep 16, 2020
86a4284
Merge branch 'branch-Level-7'
Sep 16, 2020
5eac613
Addressed conflicts between master and branch level-7
Sep 16, 2020
2ccf567
changed the location of the text file storing the list.
Sep 30, 2020
b1714d9
A-MoreOOP: Use More OOP
Oct 2, 2020
87c7bfc
Level-8: Cates and Times
Oct 2, 2020
08b6d71
Level-8(v2.0): Dates and Times
Oct 2, 2020
286a236
Level-9: Find
Oct 2, 2020
d805b90
A-JavaDoc
Oct 2, 2020
ac4816f
Merge pull request #1 from yuqiaoluolong/branch-Level-8-Dates-and-Times
yuqiaoluolong Oct 2, 2020
ce8a7eb
Merge branch 'master' of https://github.com/yuqiaoluolong/ip into bra…
Oct 2, 2020
6b613d9
Final version
Oct 2, 2020
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ src/main/resources/docs/
bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
text-ui-test/EXPECTED.TXT
3 changes: 3 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D][✘] d2 (by: Year.2015, Month.FEBRUARY, Day.20, Time: h.6, m.30)
[D][✘] e1 (by: Year.2015, Month.FEBRUARY, Day.20, Time: h.6, m.30)
[T][✘] task4
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

99 changes: 99 additions & 0 deletions src/main/java/Duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package Duke;

import Duke.DukeException.DeadlineNullException;
import Duke.DukeException.EventNullException;
import Duke.DukeException.TodoNullException;
import Duke.command.Command;
import Duke.parser.Parser;
import Duke.storage.Storage;
import Duke.taskList.TaskList;
import Duke.ui.UI;

import java.time.Month;

import static Duke.ui.UI.DOUBLEINDENTATION;
import static Duke.ui.UI.printStatement;

public class Duke {

private Storage storage;
private TaskList tasks;
private UI ui;

public Duke(String filePath) {
ui = new UI();
storage = new Storage(filePath);
//try {
tasks = new TaskList(storage.load());
/*} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
}*/
}

public void run() {
ui.showWelcome();
boolean isExit = false;
int numberOfTasks = storage.loadNumberOfTasks();
while (!isExit) {
//try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c;
if(fullCommand.contains("todo")) {
c = Parser.parseTodoCommand(fullCommand, numberOfTasks);
numberOfTasks++;
} else if(fullCommand.contains("deadline")){
c = Parser.parseDeadlineCommand(fullCommand, numberOfTasks);
numberOfTasks++;
} else if(fullCommand.contains("event")) {
c = Parser.parseEventCommand(fullCommand, numberOfTasks);
numberOfTasks++;
} else if(fullCommand.contains("help")) {
c = Parser.parseHelpCommand(numberOfTasks);
} else if(fullCommand.contains("list")){
c = Parser.parseListCommand(numberOfTasks);
} else if(fullCommand.contains("find")) {
c = Parser.parseFindCommand(fullCommand.substring(fullCommand.indexOf("find")+4).trim(),
numberOfTasks);
} else if(fullCommand.contains("done")) {
c = Parser.parseDoneCommand(fullCommand, numberOfTasks);
} else if(fullCommand.contains("delete")) {
c = Parser.parseDeleteCommand(fullCommand, numberOfTasks);
if(c.description.length() != 0) {
numberOfTasks--;
}
} else if(fullCommand.contains("bye")){
c = Parser.parseExitCommand(numberOfTasks);
} else {
c = Parser.parseExceptionCommand(numberOfTasks);
}
try{
c.execute(tasks, ui, storage);
c.sava(tasks, ui, storage);
isExit = c.isExit();
} catch (NullPointerException e) {
numberOfTasks--;
} catch (TodoNullException e) {
printStatement(DOUBLEINDENTATION +
"☹ OOPS!!! The description of a todo cannot be empty.\n");
tasks.remove(numberOfTasks-1);
numberOfTasks--;
} catch (DeadlineNullException e) {
numberOfTasks--;
} catch (EventNullException e) {
numberOfTasks--;
}

/*} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}*/
}
}

public static void main(String[] args) {
new Duke("/Users/yuqiao/Desktop/CS2113T/ip/data/duke.txt").run();
}
}
4 changes: 4 additions & 0 deletions src/main/java/Duke/DukeException/DeadlineNullException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Duke.DukeException;

public class DeadlineNullException extends Exception {
}
4 changes: 4 additions & 0 deletions src/main/java/Duke/DukeException/EventNullException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Duke.DukeException;

public class EventNullException extends Throwable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Duke.DukeException;

/**
* build InvalidStorageNullException extending Exception.
*/
public class InvalidStorageFilePathException extends Exception {
public InvalidStorageFilePathException(String s) {
}
//no other code needed
}
8 changes: 8 additions & 0 deletions src/main/java/Duke/DukeException/TodoNullException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Duke.DukeException;

/**
* build TodoNullException extending Exception.
*/
public class TodoNullException extends Exception {
//no other code needed
}
53 changes: 53 additions & 0 deletions src/main/java/Duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package Duke.command;

import Duke.DukeException.DeadlineNullException;
import Duke.DukeException.EventNullException;
import Duke.DukeException.TodoNullException;
import Duke.storage.Storage;
import Duke.taskList.TaskList;
import Duke.ui.UI;

/**
* Represents a Command with description and numberOfTasks.
* Is it an abstracted type.
*/
public class Command {
public String description;
protected int numberOfTasks = 0;

public Command(String description, int numberOfTasks) {
this.description = description;
this.numberOfTasks = numberOfTasks;
}

/**
* Execute the Command.
*/
public void execute(TaskList tasks, UI ui, Storage storage) throws TodoNullException, DeadlineNullException, EventNullException {
}

/**
* Execute the save function.
* Save the changed taskList into the file
*/
public void sava(TaskList tasks, UI ui, Storage storage){

}

/**
* Return a boolean variable indicating whether the command
* is an ExitCommand.
* If it is, return true. Else wise, return false.
*
* @return Boolean variable indicating whether the command
* is an ExitCommand.
*/
public boolean isExit() {
if(description == "bye") {
return true;
}
else {
return false;
}
}
}
58 changes: 58 additions & 0 deletions src/main/java/Duke/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package Duke.command;

import Duke.DukeException.DeadlineNullException;
import Duke.DukeException.EventNullException;
import Duke.DukeException.TodoNullException;
import Duke.storage.Storage;
import Duke.task.Deadline;
import Duke.taskList.TaskList;
import Duke.ui.UI;

import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;

import static Duke.ui.UI.*;

/**
* Represents a DeadlineCommand with description and numberOfTasks.
* A <code>deadline</code> object corresponds to a TodoCommand
* with the description and due time extracted from what entered by users.
*/
public class DeadlineCommand extends Command {
protected LocalDateTime by;

public DeadlineCommand(String description, int numberOfTasks, String by) {
super(description, numberOfTasks);
try {
this.by = LocalDateTime.parse(by);
} catch (DateTimeParseException e) {
printStatement(DOUBLEINDENTATION + "☹ OOPS!!! The time entered is not in the format(yyyy-mm-dd).\n");
}
}

/**
* Override: Execute the Command.
* add a new Deadline into the taskList.
*/
@Override
public void execute(TaskList tasks, UI ui, Storage storage) throws TodoNullException, DeadlineNullException,
EventNullException {
super.execute(tasks, ui, storage);
if(this.by.toString().length() == 0 && this.by.toString().length() == 0){
throw new DeadlineNullException();
}
tasks.add(new Deadline(this.description, this.by));
ui.printStatement(DOUBLEINDENTATION + "Got it. I've added this task:\n"
+ TRIPLEINDENTATION + tasks.get(numberOfTasks - 1).toString() + "\n" + DOUBLEINDENTATION
+ "Now you have " + (numberOfTasks) + " tasks in the list.\n");
}

/**
* Execute the save function.
* Save the changed taskList into the file
*/
@Override
public void sava(TaskList tasks, UI ui, Storage storage){
Storage.save(tasks, numberOfTasks);
}
}
45 changes: 45 additions & 0 deletions src/main/java/Duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package Duke.command;

import Duke.storage.Storage;
import Duke.taskList.TaskList;
import Duke.ui.UI;

import static Duke.ui.UI.*;

/**
* Represents a DeleteCommand with description and numberOfTasks.
* A <code>delete</code> object corresponds to a DeleteCommand
* with the description extracted from what entered by users,
* which is the index of the task users intend to delete.
*/
public class DeleteCommand extends Command {
public DeleteCommand(String description, int numberOfTasks) {
super(description, numberOfTasks);
}

/**
* Override: Execute the Command.
* Delete the task with entered index.
* Print out the delete message.
*/
@Override
public void execute(TaskList tasks, UI ui, Storage storage){
try {
printStatement(DOUBLEINDENTATION + "Noted. I've removed this task: \n" +
TRIPLEINDENTATION + tasks.get(Integer.parseInt(this.description)-1).toString() + "\n" +
DOUBLEINDENTATION + "Now you have " + (numberOfTasks-1) + " tasks in the list.\n");
tasks.remove(Integer.parseInt(this.description)-1);
} catch (NumberFormatException e) {
printStatement(DOUBLEINDENTATION + "☹ OOPS!!! You did not indicate which task to delete.\n");
}
}

/**
* Execute the save function.
* Save the changed taskList into the file
*/
@Override
public void sava(TaskList tasks, UI ui, Storage storage){
Storage.save(tasks, numberOfTasks-1);
}
}
46 changes: 46 additions & 0 deletions src/main/java/Duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package Duke.command;

import Duke.storage.Storage;
import Duke.taskList.TaskList;
import Duke.ui.UI;

import static Duke.ui.UI.*;

/**
* Represents a DoneCommand with description and numberOfTasks.
* A <code>done</code> object corresponds to a DoneCommand
* with the description extracted from what entered by users,
* which is the index of the task users intend to mark as done.
*/
public class DoneCommand extends Command {
public DoneCommand(String description, int numberOfTasks) {
super(description, numberOfTasks);
}

/**
* Override: Execute the Command.
* Mark the task with the entered index as done.
* Print out the done message.
*/
@Override
public void execute(TaskList tasks, UI ui, Storage storage){
try {
tasks.get(Integer.parseInt(this.description)- 1).markAsDone();
printStatement(DOUBLEINDENTATION + "Nice! I've marked this task as done: \n"
+ TRIPLEINDENTATION + tasks.get(Integer.parseInt(this.description) - 1).toString() + "\n");
} catch (NumberFormatException e) {
printStatement(DOUBLEINDENTATION + "☹ OOPS!!! You did not indicate which task is done.\n");
} catch (IndexOutOfBoundsException e) {
printStatement(DOUBLEINDENTATION + "☹ OOPS!!! The index is out of the list boundary.\n");
}
}

/**
* Execute the save function.
* Save the changed taskList into the file
*/
@Override
public void sava(TaskList tasks, UI ui, Storage storage){
Storage.save(tasks, numberOfTasks);
}
}
Loading