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

Add tag and untag function #52

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 13 additions & 0 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public static void main(String[] args) {
Ui.printLine();
break;

case "tag":
Ui.printLine();
Parser.tagCommand(command, list);
Ui.printLine();
break;

case "untag":
Ui.printLine();
Parser.removeTagCommand(command, list);
Ui.printLine();
break;


case "help":
Ui.printLine();
Ui.helpCommand();
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/seedu/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,40 @@ public static void uncheckCommand(String[] command, TravelActivityList list) thr
throw new OmniException("Please specify which task to uncheck");
}
}

/**
* Handles the case where the tag command is given as input
*
* @param command Command array of input string without spaces
* @param list List of travel activities
* @throws OmniException if command.length == 2
* @throws OmniException if command.length == 1
*/
public static void tagCommand(String[] command, TravelActivityList list) throws OmniException {
if (command.length == 3 && isNumeric(command[1])){
int listNumber = Integer.parseInt(command[1]);
String tag = command[2];
list.tagActivity(listNumber, tag);
} else if (command.length == 2) {
throw new OmniException("Please specify a tag name");
} else {
throw new OmniException("Please specify which task to tag");
}
}

/**
* Handles the case where the untag command is given as input
*
* @param command Command array of input string without spaces
* @param list List of travel activities
* @throws OmniException if command.length != 2 && command[1] is not numeric
*/
public static void removeTagCommand(String[] command, TravelActivityList list) throws OmniException {
if (command.length == 2 && isNumeric(command[1])) {
int listNumber = Integer.parseInt(command[1]);
list.removeTag(listNumber);
} else {
throw new OmniException("Please specify which task to remove tag");
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/seedu/duke/TravelActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public class TravelActivity {
private String travelActivity;
/** Travel activity status */
private boolean taskIsDone = false;
/** Travel activity tag */
private String tag;

public TravelActivity(String line){
travelActivity = line;
}
Expand Down Expand Up @@ -32,4 +35,20 @@ public String getPlan(){

public boolean getTaskStatus() {return taskIsDone;}

/**
* Gets the tag of the travel activity
* @return The tag of the travel activity
*/
public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

public void removeTag() {
this.tag = "";
}

}
31 changes: 31 additions & 0 deletions src/main/java/seedu/duke/TravelActivityList.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,36 @@ public void uncheckTravelActivity(int taskNumber) throws OmniException{
System.out.println(markedTask);
}

/**
* Adds a tag to travel activity
* @param taskNumber The travel activity number on the list
* @param tag The tag of travel activity
*/
public void tagActivity(int taskNumber, String tag) throws OmniException{
assert taskNumber != 0 : "There is no tasks in the list";
if (taskNumber > travelActivities.size()) {
throw new OmniException("Travel activity cannot be found");
}
int indexOfTask = taskNumber - 1;
TravelActivity taggedTask = travelActivities.get(indexOfTask);
taggedTask.setTag(tag);
System.out.println("I have tagged this task:");
System.out.println(taggedTask + "(" + tag + ")");
}

/**
* Removes the tag on a travel activity
* @param taskNumber The travel activity number on the list
*/
public void removeTag(int taskNumber) throws OmniException {
assert taskNumber != 0 : "There is no task in the list";
if (taskNumber > travelActivities.size()) {
throw new OmniException("Travel activity cannot be found");
}
int indexOfTask = taskNumber - 1;
TravelActivity taggedTask = travelActivities.get(indexOfTask);
taggedTask.removeTag();
System.out.println("Tag removed from the task:");
System.out.println(taggedTask);
}
}
Loading