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

[Brian Chow] iP #296

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
487213c
Level-1
brian16600 Jan 19, 2022
63bd8fe
Level-2. Changed the return values of levelOneRespond and implemented…
brian16600 Jan 20, 2022
63b7384
Level-3
brian16600 Jan 20, 2022
5188549
Level-3
brian16600 Jan 20, 2022
629d77c
Level-3
brian16600 Jan 21, 2022
62a2177
Level-4.
brian16600 Jan 26, 2022
49d9e0a
Level-5.
brian16600 Jan 29, 2022
89c0746
Level-6
brian16600 Jan 29, 2022
22f31af
Level-7
brian16600 Feb 2, 2022
a2b7ffd
Level-8
brian16600 Feb 3, 2022
3c16b7b
Added Parser, Storage and Tasklist
brian16600 Feb 5, 2022
633dca6
Added TaskList and Parser classes. TaskList contains the arraylist of…
brian16600 Feb 5, 2022
38a2462
Added more OOP and documentation
brian16600 Feb 5, 2022
e129edd
Added packages: duke.duke, duke.ui, duke.storage and duke.task
brian16600 Feb 5, 2022
cd020f5
Merge branch 'add-gradle-support'
brian16600 Feb 5, 2022
6ace068
Added add-gradle-support branch by merging into master
brian16600 Feb 5, 2022
33617d4
Ensured javadoc documentation is complete for all methods
brian16600 Feb 5, 2022
6da11ff
Added InputHandlerTest.java and TaskListTest.java
brian16600 Feb 6, 2022
ae099f5
Added NumberFormatException handling for delete, unmark and mark if n…
brian16600 Feb 6, 2022
390edec
Changed formatting for coding standards based on feedback
brian16600 Feb 6, 2022
2607baf
Added find and NumberFormatException in cases where non-integer is pa…
brian16600 Feb 6, 2022
aca80eb
Added JAR functionality
brian16600 Feb 12, 2022
f97ff93
Shifted into packages
brian16600 Feb 12, 2022
bb37f21
revert
brian16600 Feb 12, 2022
255fbef
Tentative changes
brian16600 Feb 12, 2022
b4458cc
Adding Duke GUI
brian16600 Feb 15, 2022
3960ddc
Add Assertions
brian16600 Feb 15, 2022
9bd5f23
Clean up text-ui-test
brian16600 Feb 15, 2022
ee148e4
Tentative changes to code quality
brian16600 Feb 15, 2022
5344d8e
Improve Code Quality based on Issue Tracker
brian16600 Feb 16, 2022
747cd67
Merge pull request #2 from brian16600/branch-A-CodeQuality
brian16600 Feb 16, 2022
fee4ebb
Update README.md
brian16600 Feb 17, 2022
e1dec30
Update README.md
brian16600 Feb 17, 2022
c126d99
Create README.md
brian16600 Feb 17, 2022
133c672
Update README.md
brian16600 Feb 17, 2022
5d7d4fb
Update README.md
brian16600 Feb 17, 2022
87677f2
Update README.md
brian16600 Feb 17, 2022
805ab54
Update README.md
brian16600 Feb 17, 2022
effc8c7
Update README.md
brian16600 Feb 17, 2022
5e3b5c9
Update README.md
brian16600 Feb 17, 2022
9004041
Temporary addition of Snooze.
brian16600 Feb 17, 2022
4c29aa2
Add snooze command
brian16600 Feb 17, 2022
68e9fea
Merge branch 'master' of https://github.com/brian16600/ip
brian16600 Feb 17, 2022
436be42
Add Ui.png
brian16600 Feb 17, 2022
38d5c9a
Add Ui.png
brian16600 Feb 17, 2022
56d537e
Update README.md
brian16600 Feb 17, 2022
18b7995
Update README.md
brian16600 Feb 17, 2022
ca00570
Update README.md
brian16600 Feb 17, 2022
4460756
Update README.md
brian16600 Feb 17, 2022
a58d8da
Update README.md
brian16600 Feb 17, 2022
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
Prev Previous commit
Next Next commit
Added find and NumberFormatException in cases where non-integer is pa…
…ssed in.
brian16600 committed Feb 6, 2022
commit 2607baf257cc90010fdffe3f2eb1e4b9a43f96ce
15 changes: 14 additions & 1 deletion src/main/java/InputHandler.java
Original file line number Diff line number Diff line change
@@ -116,8 +116,20 @@ public boolean handleInput(String input) throws DukeException, IOException {
} else {
throw new DukeException("Wrong usage of delete! Correct usage: delete [index]");
}

case "find":
if (splitInput.length > 1) {
parser.parse(CommandType.FIND, this.storage, splitInput);
return false;
} else {
throw new DukeException("Uh oh! It seems like you did not specify what to find");
}

case "bye":
return true;



default:
throw new DukeException(":( OOPS!!! I'm sorry, but I don't know what that means! Possible commands: " +
"todo [task], event [task] /at [time],"
@@ -144,7 +156,8 @@ enum CommandType {
LIST,
MARK,
UNMARK,
DELETE
DELETE,
FIND
}
}

40 changes: 38 additions & 2 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -8,8 +8,12 @@
import duke.task.Task;
import duke.task.Todo;
import duke.task.Deadline;

import java.time.format.DateTimeParseException;

import java.util.Arrays;
import java.util.ArrayList;

import java.io.IOException;

public class Parser {
@@ -24,11 +28,13 @@ public class Parser {
public Task parse(InputHandler.CommandType type, String[] splitInput) throws DukeException {

Choose a reason for hiding this comment

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

Perhaps it may be easier to understand if the 2 parse functions were combined into 1 :)

switch (type) {
case TODO:
//Removes the todo command word: i.e. todo task -> task
String[] nameArray = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String todoName = String.join(" ", nameArray);
return new Todo(todoName);

case EVENT:
//Removes the event command word and separates into date and time (optional)
String[] stringArrayExcludingEvent = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String stringExcludingEvent = String.join(" ", stringArrayExcludingEvent);
String[] eventNameAndTimeArray = stringExcludingEvent.split("/at ");
@@ -40,11 +46,13 @@ public Task parse(InputHandler.CommandType type, String[] splitInput) throws Duk
Event newEvent = (eventTimeArray.length > 1) ? new Event(eventName, eventTimeArray[0], eventTimeArray[1]) : new Event(eventName, eventTimeArray[0]);
return newEvent;
} catch (DateTimeParseException e) {
//Datetime unable to be parsed
throw new DukeException(":( OOPS!!! The correct format for date and time is yyyy-mm-dd and hh:mm");

}

case DEADLINE:
//Removes the deadline command word and separates into date and time (optional)
String[] stringArrayExcludingDeadline = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String stringExcludingDeadline = String.join(" ", stringArrayExcludingDeadline);
String[] deadlineNameAndTimeArray = stringExcludingDeadline.split("/by ");
@@ -56,6 +64,7 @@ public Task parse(InputHandler.CommandType type, String[] splitInput) throws Duk
Deadline newDeadline = (deadlineTimeArray.length > 1) ? new Deadline(deadlineName, deadlineTimeArray[0], deadlineTimeArray[1]) : new Deadline(deadlineName, deadlineTimeArray[0]);
return newDeadline;
} catch (DateTimeParseException e) {
//Datetime unable to be parsed
throw new DukeException(":( OOPS!!! The correct format for date and time is yyyy-mm-dd and hh:mm");

}
@@ -82,40 +91,67 @@ public void parse(InputHandler.CommandType type, Storage storage, String[] split
break;

case MARK:

//Marks task by index
try {
int taskToBeMarkedIndex = Integer.parseInt(splitInput[1]) - 1;
Task taskToBeMarked = storage.get(taskToBeMarkedIndex);
System.out.println("Nice! I've marked this task as done:\n");
taskToBeMarked.setMarkedTask();
} catch (NumberFormatException e) {
//Addresses the error of a non-integer being passed in
System.out.println("Make sure mark is in the format: mark [index]!");
}
break;

case UNMARK:

//Unmarks task by index
try {
int taskToBeUnmarkedIndex = Integer.parseInt(splitInput[1]) - 1;
Task taskToBeUnmarked = storage.get(taskToBeUnmarkedIndex);
System.out.println("OK, I've marked this task as not done yet:\n");
taskToBeUnmarked.setUnmarkedTask();
} catch (NumberFormatException e) {
//Addresses the issue of a non-integer being passed in
System.out.println("Make sure mark is in the format: mark [index]!");
}
break;

case DELETE:
//Delete task by index
try {
int idx = Integer.parseInt(splitInput[1]) - 1;
Task taskToBeDeleted = storage.get(idx);
storage.deleteData(idx);
System.out.println("Noted. I've removed this task:\n" + taskToBeDeleted + "\nNow you have " + storage.taskListSize() + " tasks in the list");
} catch (NumberFormatException e) {
//Addresses the issue of a non-integer being passed in
System.out.println("Make sure mark is in the format: mark [index]!");
}
break;

case FIND:
//Removes the find command and iterates through the TaskList to find a task name that contains the keyword
String[] stringArrayExcludingFind = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String nameOfKeyWord = String.join(" ", stringArrayExcludingFind);
ArrayList<Task> arrayOfTasks = storage.accessTaskList().list;
ArrayList<Integer> indexOfFoundObjects = new ArrayList<>();
for (int i = 0; i < arrayOfTasks.size(); i++) {
Task currentTask = arrayOfTasks.get(i);
if (currentTask.name.contains(nameOfKeyWord)) {
indexOfFoundObjects.add(i);
}
}
if (!indexOfFoundObjects.isEmpty()) {
//Task found and print
for (int j = 0; j < indexOfFoundObjects.size(); j++) {
System.out.println((j + 1) + "." + storage.get(indexOfFoundObjects.get(j)));
}
break;
} else {
//Unable to find
System.out.println("Uh oh! No task matches the description you've given :(");
}

default:
throw new DukeException(":( OOPS!!! I'm sorry, but I don't know what that means! Possible commands: todo [task], event [task] /at [time],"
+ " deadline [task] /by [time], mark [index], unmark [index], delete [index], bye");
8 changes: 6 additions & 2 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@
import java.io.FileWriter;

public class Storage {
TaskList taskList;
String FILEPATH = "data/data.txt";
private TaskList taskList;
final String FILEPATH = "data/data.txt";

/**
* Constructs a Storage object. Loads the data from data/data.txt. if no data dir or data.txt is found, create an empty one
@@ -157,4 +157,8 @@ public int taskListSize() {
return this.taskList.size();
}

public TaskList accessTaskList() {
return this.taskList;
}

}
2 changes: 1 addition & 1 deletion src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
import duke.task.Task;
import java.util.ArrayList;
public class TaskList {
ArrayList<Task> list;
public ArrayList<Task> list;

/**
* Constructor for TaskList. Initialises an empty ArrayList<Task>