diff --git a/src/main/java/seedu/omnitravel/error_handlers/CheckParameters.java b/src/main/java/seedu/omnitravel/errorhandlers/CheckParameters.java similarity index 96% rename from src/main/java/seedu/omnitravel/error_handlers/CheckParameters.java rename to src/main/java/seedu/omnitravel/errorhandlers/CheckParameters.java index 2b89fb1654..7c2e8b5ab2 100644 --- a/src/main/java/seedu/omnitravel/error_handlers/CheckParameters.java +++ b/src/main/java/seedu/omnitravel/errorhandlers/CheckParameters.java @@ -1,75 +1,75 @@ -package seedu.omnitravel.error_handlers; - -import seedu.omnitravel.ui.Ui; - -import java.io.IOException; -import java.time.DateTimeException; -import java.util.NoSuchElementException; - -import static seedu.omnitravel.parser.Parser.isNumeric; - -public class CheckParameters { - - /** - * Checks for all possible input errors that users may make and throws the corresponding exceptions - * - * @param input Input array that users placed into the chatbot - * @throws OmniException when any of the corresponding input format is wrong - */ - public static void addExceptions(String[] input) throws OmniException{ - if (input.length >= 4 && input[1].isBlank()) { - throw new OmniException("The description cannot be empty!"); - } else if (input.length >= 4 && input[2].isBlank()) { - throw new OmniException("The date cannot be empty!"); - } else if (input.length >= 4 && input[3].isBlank()) { - throw new OmniException("The duration cannot be empty!"); - } else if (input.length >= 5 && input[4].isBlank()) { - throw new OmniException("The tag cannot be empty!"); - } else if (input.length < 4 || input[3].contains("/tag")){ - throw new OmniException("Please check that your add command is in this format: add DESCRIPTION " + - "/date YYYY-MM-DD /duration DURATION" - + " or add DESCRIPTION /date YYYY-MM-DD /duration DURATION /tag TAG"); - } - } - - /** - * Checks for all possible input errors that users may make when updating and throws the corresponding exceptions - * - * @param command Command array that users placed into the chatbot - * @throws OmniException when any of the corresponding input format is wrong - */ - public static void updateExceptions(String[] command) throws OmniException { - if (command.length >= 4 && (command[1].isBlank() || !isNumeric(command[1]))) { - throw new OmniException("The update index cannot be empty or non numerical!"); - } else if (command.length >= 4 && command[2].isBlank()) { - throw new OmniException("The date cannot be empty!"); - } else if (command.length >= 4 && command[3].isBlank()) { - throw new OmniException("The duration cannot be empty!"); - } else if(command.length >= 5 && command[4].isBlank()){ - throw new OmniException("The tag cannot be empty!"); - } else if (command.length >= 4 && !command[3].contains("/tag")) { - throw new OmniException("Please check that your update command is in this format: update INDEX " + - "/date YYYY-MM-DD /duration DURATION" - + " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG"); - } - } - - /** - * Checks for all format errors in the user input and throes the correct exceptions - * - * @param exception Exception thrown - */ - public static void handleException(Exception exception) { - if (exception instanceof OmniException) { - Ui.printException((OmniException) exception); - } else if (exception instanceof NoSuchElementException) { - Ui.printNoSuchElementException((NoSuchElementException) exception); - } else if (exception instanceof NumberFormatException) { - Ui.printNumberTooLargeException((NumberFormatException) exception); - } else if (exception instanceof DateTimeException) { - Ui.printDateTimeExceptionError(); - } else if (exception instanceof IOException) { - Ui.printSavingError(); - } - } -} +package seedu.omnitravel.errorhandlers; + +import seedu.omnitravel.ui.Ui; + +import java.io.IOException; +import java.time.DateTimeException; +import java.util.NoSuchElementException; + +import static seedu.omnitravel.parser.Parser.isNumeric; + +public class CheckParameters { + + /** + * Checks for all possible input errors that users may make and throws the corresponding exceptions + * + * @param input Input array that users placed into the chatbot + * @throws OmniException when any of the corresponding input format is wrong + */ + public static void addExceptions(String[] input) throws OmniException{ + if (input.length >= 4 && input[1].isBlank()) { + throw new OmniException("The description cannot be empty!"); + } else if (input.length >= 4 && input[2].isBlank()) { + throw new OmniException("The date cannot be empty!"); + } else if (input.length >= 4 && input[3].isBlank()) { + throw new OmniException("The duration cannot be empty!"); + } else if (input.length >= 5 && input[4].isBlank()) { + throw new OmniException("The tag cannot be empty!"); + } else if (input.length < 4 || input[3].contains("/tag")){ + throw new OmniException("Please check that your add command is in this format: add DESCRIPTION " + + "/date YYYY-MM-DD /duration DURATION" + + " or add DESCRIPTION /date YYYY-MM-DD /duration DURATION /tag TAG"); + } + } + + /** + * Checks for all possible input errors that users may make when updating and throws the corresponding exceptions + * + * @param command Command array that users placed into the chatbot + * @throws OmniException when any of the corresponding input format is wrong + */ + public static void updateExceptions(String[] command) throws OmniException { + if (command.length >= 4 && (command[1].isBlank() || !isNumeric(command[1]))) { + throw new OmniException("The update index cannot be empty or non numerical!"); + } else if (command.length >= 4 && command[2].isBlank()) { + throw new OmniException("The date cannot be empty!"); + } else if (command.length >= 4 && command[3].isBlank()) { + throw new OmniException("The duration cannot be empty!"); + } else if(command.length >= 5 && command[4].isBlank()){ + throw new OmniException("The tag cannot be empty!"); + } else if (command.length >= 4 && !command[3].contains("/tag")) { + throw new OmniException("Please check that your update command is in this format: update INDEX " + + "/date YYYY-MM-DD /duration DURATION" + + " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG"); + } + } + + /** + * Checks for all format errors in the user input and throes the correct exceptions + * + * @param exception Exception thrown + */ + public static void handleException(Exception exception) { + if (exception instanceof OmniException) { + Ui.printException((OmniException) exception); + } else if (exception instanceof NoSuchElementException) { + Ui.printNoSuchElementException((NoSuchElementException) exception); + } else if (exception instanceof NumberFormatException) { + Ui.printNumberTooLargeException((NumberFormatException) exception); + } else if (exception instanceof DateTimeException) { + Ui.printDateTimeExceptionError(); + } else if (exception instanceof IOException) { + Ui.printSavingError(); + } + } +} diff --git a/src/main/java/seedu/omnitravel/error_handlers/OmniException.java b/src/main/java/seedu/omnitravel/errorhandlers/OmniException.java similarity index 73% rename from src/main/java/seedu/omnitravel/error_handlers/OmniException.java rename to src/main/java/seedu/omnitravel/errorhandlers/OmniException.java index dcc9422adf..64ac779a5d 100644 --- a/src/main/java/seedu/omnitravel/error_handlers/OmniException.java +++ b/src/main/java/seedu/omnitravel/errorhandlers/OmniException.java @@ -1,7 +1,7 @@ -package seedu.omnitravel.error_handlers; - -public class OmniException extends Exception { - public OmniException(String errorMessage){ - super(errorMessage); - } -} +package seedu.omnitravel.errorhandlers; + +public class OmniException extends Exception { + public OmniException(String errorMessage){ + super(errorMessage); + } +} diff --git a/src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java b/src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java index 6f201688c9..70f0eaaeea 100644 --- a/src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java +++ b/src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java @@ -1,9 +1,9 @@ package seedu.omnitravel.omnitravel; import seedu.omnitravel.parser.Parser; -import seedu.omnitravel.travel_activity_types.TravelActivityList; +import seedu.omnitravel.travelactivitytypes.TravelActivityList; import seedu.omnitravel.ui.Ui; -import seedu.omnitravel.error_handlers.CheckParameters; -import seedu.omnitravel.error_handlers.OmniException; +import seedu.omnitravel.errorhandlers.CheckParameters; +import seedu.omnitravel.errorhandlers.OmniException; import seedu.omnitravel.storage.FileSave; import java.io.IOException; diff --git a/src/main/java/seedu/omnitravel/parser/Parser.java b/src/main/java/seedu/omnitravel/parser/Parser.java index d73b44892e..5f9bd3145f 100644 --- a/src/main/java/seedu/omnitravel/parser/Parser.java +++ b/src/main/java/seedu/omnitravel/parser/Parser.java @@ -1,11 +1,11 @@ package seedu.omnitravel.parser; -import seedu.omnitravel.travel_activity_types.TravelActivityList; -import seedu.omnitravel.error_handlers.CheckParameters; -import seedu.omnitravel.error_handlers.OmniException; -import seedu.omnitravel.travel_activity_types.Accommodation; -import seedu.omnitravel.travel_activity_types.Food; -import seedu.omnitravel.travel_activity_types.Landmark; -import seedu.omnitravel.travel_activity_types.TravelActivity; +import seedu.omnitravel.travelactivitytypes.TravelActivityList; +import seedu.omnitravel.errorhandlers.CheckParameters; +import seedu.omnitravel.errorhandlers.OmniException; +import seedu.omnitravel.travelactivitytypes.Accommodation; +import seedu.omnitravel.travelactivitytypes.Food; +import seedu.omnitravel.travelactivitytypes.Landmark; +import seedu.omnitravel.travelactivitytypes.TravelActivity; import seedu.omnitravel.ui.Ui; import java.time.LocalDate; diff --git a/src/main/java/seedu/omnitravel/storage/FileSave.java b/src/main/java/seedu/omnitravel/storage/FileSave.java index cf4b74d690..c37274fe49 100644 --- a/src/main/java/seedu/omnitravel/storage/FileSave.java +++ b/src/main/java/seedu/omnitravel/storage/FileSave.java @@ -1,9 +1,9 @@ package seedu.omnitravel.storage; -import seedu.omnitravel.travel_activity_types.TravelActivityList; -import seedu.omnitravel.travel_activity_types.Accommodation; -import seedu.omnitravel.travel_activity_types.Food; -import seedu.omnitravel.travel_activity_types.Landmark; -import seedu.omnitravel.travel_activity_types.TravelActivity; +import seedu.omnitravel.travelactivitytypes.TravelActivityList; +import seedu.omnitravel.travelactivitytypes.Accommodation; +import seedu.omnitravel.travelactivitytypes.Food; +import seedu.omnitravel.travelactivitytypes.Landmark; +import seedu.omnitravel.travelactivitytypes.TravelActivity; import java.io.FileWriter; import java.io.FileNotFoundException; diff --git a/src/main/java/seedu/omnitravel/travel_activity_types/Accommodation.java b/src/main/java/seedu/omnitravel/travelactivitytypes/Accommodation.java similarity index 86% rename from src/main/java/seedu/omnitravel/travel_activity_types/Accommodation.java rename to src/main/java/seedu/omnitravel/travelactivitytypes/Accommodation.java index bd749b4a09..534b0476f6 100644 --- a/src/main/java/seedu/omnitravel/travel_activity_types/Accommodation.java +++ b/src/main/java/seedu/omnitravel/travelactivitytypes/Accommodation.java @@ -1,18 +1,18 @@ -package seedu.omnitravel.travel_activity_types; - -import java.time.LocalDate; - -public class Accommodation extends TravelActivity { - private LocalDate date; - private String duration; - - public Accommodation(String line, LocalDate date, String duration, String tag, String expense){ - super(line, date, duration, tag, expense); - } - - @Override - public String toString(){ - return "Accommodation: " + super.toString(); - } - -} +package seedu.omnitravel.travelactivitytypes; + +import java.time.LocalDate; + +public class Accommodation extends TravelActivity { + private LocalDate date; + private String duration; + + public Accommodation(String line, LocalDate date, String duration, String tag, String expense){ + super(line, date, duration, tag, expense); + } + + @Override + public String toString(){ + return "Accommodation: " + super.toString(); + } + +} diff --git a/src/main/java/seedu/omnitravel/travel_activity_types/Food.java b/src/main/java/seedu/omnitravel/travelactivitytypes/Food.java similarity index 84% rename from src/main/java/seedu/omnitravel/travel_activity_types/Food.java rename to src/main/java/seedu/omnitravel/travelactivitytypes/Food.java index 2a72636849..d8d0352723 100644 --- a/src/main/java/seedu/omnitravel/travel_activity_types/Food.java +++ b/src/main/java/seedu/omnitravel/travelactivitytypes/Food.java @@ -1,14 +1,14 @@ -package seedu.omnitravel.travel_activity_types; - -import java.time.LocalDate; - -public class Food extends TravelActivity { - public Food(String line, LocalDate date, String duration, String tag, String expense){ - super(line, date, duration, tag, expense); - } - - @Override - public String toString(){ - return "Food: " + super.toString(); - } -} +package seedu.omnitravel.travelactivitytypes; + +import java.time.LocalDate; + +public class Food extends TravelActivity { + public Food(String line, LocalDate date, String duration, String tag, String expense){ + super(line, date, duration, tag, expense); + } + + @Override + public String toString(){ + return "Food: " + super.toString(); + } +} diff --git a/src/main/java/seedu/omnitravel/travel_activity_types/Landmark.java b/src/main/java/seedu/omnitravel/travelactivitytypes/Landmark.java similarity index 84% rename from src/main/java/seedu/omnitravel/travel_activity_types/Landmark.java rename to src/main/java/seedu/omnitravel/travelactivitytypes/Landmark.java index 475ea9811d..5c10b1384c 100644 --- a/src/main/java/seedu/omnitravel/travel_activity_types/Landmark.java +++ b/src/main/java/seedu/omnitravel/travelactivitytypes/Landmark.java @@ -1,13 +1,13 @@ -package seedu.omnitravel.travel_activity_types; - -import java.time.LocalDate; - -public class Landmark extends TravelActivity { - public Landmark(String line, LocalDate date, String duration, String tag, String expense){ - super(line, date, duration, tag, expense); - } - @Override - public String toString(){ - return "Landmark: " + super.toString(); - } -} +package seedu.omnitravel.travelactivitytypes; + +import java.time.LocalDate; + +public class Landmark extends TravelActivity { + public Landmark(String line, LocalDate date, String duration, String tag, String expense){ + super(line, date, duration, tag, expense); + } + @Override + public String toString(){ + return "Landmark: " + super.toString(); + } +} diff --git a/src/main/java/seedu/omnitravel/travel_activity_types/TravelActivity.java b/src/main/java/seedu/omnitravel/travelactivitytypes/TravelActivity.java similarity index 93% rename from src/main/java/seedu/omnitravel/travel_activity_types/TravelActivity.java rename to src/main/java/seedu/omnitravel/travelactivitytypes/TravelActivity.java index e8aec6bf75..91fd0babda 100644 --- a/src/main/java/seedu/omnitravel/travel_activity_types/TravelActivity.java +++ b/src/main/java/seedu/omnitravel/travelactivitytypes/TravelActivity.java @@ -1,104 +1,104 @@ -package seedu.omnitravel.travel_activity_types; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; - -public class TravelActivity { - /** Travel activity description */ - private String travelActivity; - /** Travel activity date */ - private LocalDate date; - /** Travel activity duration */ - private String duration; - /** Travel activity status */ - private boolean activityIsDone = false; - /** Travel activity tag */ - private String tag; - /** Travel activity expense */ - private String expense; - - - public TravelActivity(String description, LocalDate date, String duration, String tag, String expense){ - travelActivity = description; - this.date = date; - this.duration = duration; - this.tag = tag; - this.expense = expense; - } - - @Override - public String toString(){ - return travelActivity + " :" + date.format(DateTimeFormatter.ofPattern("d MMM yyyy")) + " :" + duration; - - } - - /** - * Sets the status of the activity to complete or incomplete - * @param activityIsDone activity status - */ - public void setActivityStatus(boolean activityIsDone){ - this.activityIsDone = activityIsDone; - } - - /** - * Gets the description of the travel activity - * @return The description of the travel activity - */ - public String getPlan(){ - return travelActivity; - } - - public boolean getActivityStatus() { - return activityIsDone; - } - - /** - * 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 = ""; - } - - public void setDate(LocalDate date){ - this.date = date; - } - - public LocalDate getDate(){ - return date; - } - - public void setDuration(String duration){ - this.duration = duration; - } - - public String getDuration(){ - return duration; - } - - /** - * Gets the expense of the travel activity - * @return The tag of the travel activity - */ - public String getExpense() { - return expense; - } - - public void setExpense(String expense) { - this.expense = expense; - } - - public void removeExpense() { - this.expense = ""; - } - -} - +package seedu.omnitravel.travelactivitytypes; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +public class TravelActivity { + /** Travel activity description */ + private String travelActivity; + /** Travel activity date */ + private LocalDate date; + /** Travel activity duration */ + private String duration; + /** Travel activity status */ + private boolean activityIsDone = false; + /** Travel activity tag */ + private String tag; + /** Travel activity expense */ + private String expense; + + + public TravelActivity(String description, LocalDate date, String duration, String tag, String expense){ + travelActivity = description; + this.date = date; + this.duration = duration; + this.tag = tag; + this.expense = expense; + } + + @Override + public String toString(){ + return travelActivity + " :" + date.format(DateTimeFormatter.ofPattern("d MMM yyyy")) + " :" + duration; + + } + + /** + * Sets the status of the activity to complete or incomplete + * @param activityIsDone activity status + */ + public void setActivityStatus(boolean activityIsDone){ + this.activityIsDone = activityIsDone; + } + + /** + * Gets the description of the travel activity + * @return The description of the travel activity + */ + public String getPlan(){ + return travelActivity; + } + + public boolean getActivityStatus() { + return activityIsDone; + } + + /** + * 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 = ""; + } + + public void setDate(LocalDate date){ + this.date = date; + } + + public LocalDate getDate(){ + return date; + } + + public void setDuration(String duration){ + this.duration = duration; + } + + public String getDuration(){ + return duration; + } + + /** + * Gets the expense of the travel activity + * @return The tag of the travel activity + */ + public String getExpense() { + return expense; + } + + public void setExpense(String expense) { + this.expense = expense; + } + + public void removeExpense() { + this.expense = ""; + } + +} + diff --git a/src/main/java/seedu/omnitravel/travel_activity_types/TravelActivityList.java b/src/main/java/seedu/omnitravel/travelactivitytypes/TravelActivityList.java similarity index 96% rename from src/main/java/seedu/omnitravel/travel_activity_types/TravelActivityList.java rename to src/main/java/seedu/omnitravel/travelactivitytypes/TravelActivityList.java index 709a8f4966..57fa9804b5 100644 --- a/src/main/java/seedu/omnitravel/travel_activity_types/TravelActivityList.java +++ b/src/main/java/seedu/omnitravel/travelactivitytypes/TravelActivityList.java @@ -1,292 +1,292 @@ -package seedu.omnitravel.travel_activity_types; -import seedu.omnitravel.error_handlers.OmniException; -import seedu.omnitravel.ui.Ui; - -import java.time.LocalDate; -import java.util.ArrayList; -import java.util.logging.Logger; - - -public class TravelActivityList { - private static Logger logger = Logger.getLogger("TravelActivityListLogger"); - /** Array of travel activity */ - private ArrayList travelActivities; - - /** Number of TravelActivities */ - private int noOfActivities = 0; - public TravelActivityList() { - travelActivities = new ArrayList<>(); - } - - - /** - * Adds travel activity to the travel activity list - * @param travelActivity The travel activity - */ - public void addTravelActivity(TravelActivity travelActivity){ - //logger.log(Level.INFO, "addKeyword function started"); - int initialListSize = noOfActivities; - travelActivities.add(travelActivity); - //logger.log(Level.INFO, "travelActivity is added"); - noOfActivities += 1; - int newSize = noOfActivities; - assert newSize == initialListSize + 1 :"There is an error with list size!"; - } - - /** - * Prints out all the travel activities - */ - public void listTravelActivities(){ - int activityCount = 0; - for (TravelActivity activity: travelActivities) { - if (activity == null) { - break; - } - activityCount++; - Ui.printActivity(activity, activityCount); - } - int finalactivityCount = noOfActivities; - assert finalactivityCount == activityCount : "Index out of bounds while listing activities"; - } - - /** - * returns the number of travel activities in the list - * @return the number of travel activities - */ - public int getNoOfTravelActivities(){ - return noOfActivities; - } - /** - * Removes travel activity from the travel activity list - * @param activityNumber The travel activity number on the list - */ - public void removeTravelActivity(int activityNumber) throws OmniException { - assert activityNumber != 0 :"There is not activities in the list"; - if(activityNumber > travelActivities.size() || (activityNumber <= 0)){ - throw new OmniException("Travel activity cannot be found!"); - } - int indexOfActivity = activityNumber - 1; - int initialListSize = noOfActivities; - TravelActivity removedActivity = travelActivities.get(indexOfActivity); - travelActivities.remove(indexOfActivity); - System.out.println("I have removed this activity:"); - System.out.println(removedActivity); - noOfActivities-=1; - int newSize = noOfActivities; - assert newSize == initialListSize - 1 :"There is an error with list size!"; - } - - - public String getDescription(String plan){ - for(TravelActivity travelActivity: travelActivities){ - if(travelActivity.getPlan().equals(plan)){ - return travelActivity.getPlan(); - } - } - return "cant be found"; - } - - /** - * Finds all activities in the TravelActivity list that contains a keyword specified - * by the user. - * - * @param activityName keyword specified by the user to find activities in the TravelActivity list - * related to the keyword. - */ - - public void searchKeyword (String activityName) { - int foundCounter = 0; - for (TravelActivity travelActivity : travelActivities) { - if (travelActivity.getPlan().contains(activityName) && - !travelActivity.getPlan().isEmpty()) { - foundCounter += 1; - if (foundCounter == 1) { - System.out.println("Here are what you are looking for:"); - } - Ui.printActivity(travelActivity, foundCounter); - - } - } - if (foundCounter == 0) { - System.out.println("Sorry I could not find what you are looking for."); - } - } - - /** - * Checks travel activity as completed - * @param activityNumber The travel activity number on the list - */ - public void checkTravelActivity(int activityNumber) throws OmniException{ - - assert activityNumber != 0 : "There is not activities in the list"; - if (activityNumber > travelActivities.size() || (activityNumber <= 0)) { - throw new OmniException("Travel activity cannot be found"); - } - int indexOfActivity = activityNumber - 1; - TravelActivity markedActivity = travelActivities.get(indexOfActivity); - markedActivity.setActivityStatus(true); - System.out.println("I have checked this activity:"); - System.out.println(markedActivity); - } - - /** - * Unchecks travel activity and sets it to uncompleted - * @param activityNumber The travel activity number on the list - */ - public void uncheckTravelActivity(int activityNumber) throws OmniException{ - assert activityNumber != 0 : "There is not activities in the list"; - if (activityNumber > travelActivities.size() || (activityNumber <= 0)) { - throw new OmniException("Travel activity cannot be found"); - } - int indexOfActivity = activityNumber - 1; - TravelActivity markedActivity = travelActivities.get(indexOfActivity); - markedActivity.setActivityStatus(false); - System.out.println("I have unchecked this activity:"); - System.out.println(markedActivity); - } - - - /** - * 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() || (taskNumber <= 0)) { - 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() || (taskNumber <= 0)) { - 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); - } - - /** - * Updates the date, duration and tag of the travel activity - * @param travelActivityNumber The index of the travel activity - * @param date The new date of the travel activity - * @param duration The new duration of the travel activity - * @param tag The new tag of the travel activity - * @throws OmniException Thrown if the index of the travel activity cannot be found - */ - public void updateTravelActivity(int travelActivityNumber, LocalDate date, String duration, String tag) - throws OmniException{ - if (travelActivityNumber > travelActivities.size() || (travelActivityNumber <= 0)){ - throw new OmniException("Travel activity cannot be found"); - } - int indexOfTravelActivity = travelActivityNumber-1; - TravelActivity updatedTravelActivity = travelActivities.get(indexOfTravelActivity); - String oldTravelActivity = (updatedTravelActivity.toString() - + " (" + updatedTravelActivity.getTag() + ")"); - updatedTravelActivity.setDate(date); - updatedTravelActivity.setDuration(duration); - updatedTravelActivity.setTag(tag); - System.out.println("I have updated this task\nfrom: " + oldTravelActivity + - "\nto: " + updatedTravelActivity + " (" + updatedTravelActivity.getTag() + ")"); - } - - public ArrayList getTravelActivities () { - return travelActivities; - } - - /** - * Find all the tasks with a particular tag and prints them out - * - * @param tag The tag of tasks that the user wants to find - */ - - public void findTag(String tag){ - int foundCounter = 0; - for (TravelActivity travelActivity : travelActivities) { - if (travelActivity.getTag().contains(tag) && - !travelActivity.getTag().isEmpty()) { - foundCounter += 1; - if (foundCounter == 1) { - System.out.println("Here are what you are looking for:"); - } - Ui.printActivity(travelActivity, foundCounter); - } - } - if (foundCounter == 0) { - System.out.println("Sorry I could not find what you are looking for."); - } - } - - /** - * Find all the tasks of a particular type and prints them out - * - * @param type The type of tasks that the user wants to find - */ - - public void findType(String type){ - int foundCounter = 0; - - for (TravelActivity activity: travelActivities){ - if(activity.getClass().getSimpleName().equals(type)){ - foundCounter += 1; - if (foundCounter == 1) { - System.out.println("Here are what you are looking for:"); - } - Ui.printActivity(activity, foundCounter); - } - } - if (foundCounter == 0) { - System.out.println("Sorry I could not find what you are looking for."); - } - } - - - - /** - * Adds expense to travel activity - * @param taskNumber The travel activity number on the list - * @param expense The expense of travel activity - */ - public void expenseActivity(int taskNumber, String expense) throws OmniException { - assert taskNumber != 0 : "There is no tasks in the list"; - if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { - throw new OmniException("Travel activity cannot be found"); - } - int indexOfTask = taskNumber - 1; - TravelActivity task = travelActivities.get(indexOfTask); - task.setExpense(expense); - System.out.println("I have added expense for this task:"); - System.out.println(task + " (" + expense + ")"); - } - - /** - * Removes the expense on a travel activity - * @param taskNumber The travel activity number on the list - */ - public void removeExpense(int taskNumber) throws OmniException { - assert taskNumber != 0 : "There is no task in the list"; - if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { - throw new OmniException("Travel activity cannot be found"); - } - int indexOfTask = taskNumber - 1; - TravelActivity task = travelActivities.get(indexOfTask); - task.removeExpense(); - System.out.println("Expense removed from the task:"); - System.out.println(task); - } - - -} +package seedu.omnitravel.travelactivitytypes; +import seedu.omnitravel.errorhandlers.OmniException; +import seedu.omnitravel.ui.Ui; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.logging.Logger; + + +public class TravelActivityList { + private static Logger logger = Logger.getLogger("TravelActivityListLogger"); + /** Array of travel activity */ + private ArrayList travelActivities; + + /** Number of TravelActivities */ + private int noOfActivities = 0; + public TravelActivityList() { + travelActivities = new ArrayList<>(); + } + + + /** + * Adds travel activity to the travel activity list + * @param travelActivity The travel activity + */ + public void addTravelActivity(TravelActivity travelActivity){ + //logger.log(Level.INFO, "addKeyword function started"); + int initialListSize = noOfActivities; + travelActivities.add(travelActivity); + //logger.log(Level.INFO, "travelActivity is added"); + noOfActivities += 1; + int newSize = noOfActivities; + assert newSize == initialListSize + 1 :"There is an error with list size!"; + } + + /** + * Prints out all the travel activities + */ + public void listTravelActivities(){ + int activityCount = 0; + for (TravelActivity activity: travelActivities) { + if (activity == null) { + break; + } + activityCount++; + Ui.printActivity(activity, activityCount); + } + int finalactivityCount = noOfActivities; + assert finalactivityCount == activityCount : "Index out of bounds while listing activities"; + } + + /** + * returns the number of travel activities in the list + * @return the number of travel activities + */ + public int getNoOfTravelActivities(){ + return noOfActivities; + } + /** + * Removes travel activity from the travel activity list + * @param activityNumber The travel activity number on the list + */ + public void removeTravelActivity(int activityNumber) throws OmniException { + assert activityNumber != 0 :"There is not activities in the list"; + if(activityNumber > travelActivities.size() || (activityNumber <= 0)){ + throw new OmniException("Travel activity cannot be found!"); + } + int indexOfActivity = activityNumber - 1; + int initialListSize = noOfActivities; + TravelActivity removedActivity = travelActivities.get(indexOfActivity); + travelActivities.remove(indexOfActivity); + System.out.println("I have removed this activity:"); + System.out.println(removedActivity); + noOfActivities-=1; + int newSize = noOfActivities; + assert newSize == initialListSize - 1 :"There is an error with list size!"; + } + + + public String getDescription(String plan){ + for(TravelActivity travelActivity: travelActivities){ + if(travelActivity.getPlan().equals(plan)){ + return travelActivity.getPlan(); + } + } + return "cant be found"; + } + + /** + * Finds all activities in the TravelActivity list that contains a keyword specified + * by the user. + * + * @param activityName keyword specified by the user to find activities in the TravelActivity list + * related to the keyword. + */ + + public void searchKeyword (String activityName) { + int foundCounter = 0; + for (TravelActivity travelActivity : travelActivities) { + if (travelActivity.getPlan().contains(activityName) && + !travelActivity.getPlan().isEmpty()) { + foundCounter += 1; + if (foundCounter == 1) { + System.out.println("Here are what you are looking for:"); + } + Ui.printActivity(travelActivity, foundCounter); + + } + } + if (foundCounter == 0) { + System.out.println("Sorry I could not find what you are looking for."); + } + } + + /** + * Checks travel activity as completed + * @param activityNumber The travel activity number on the list + */ + public void checkTravelActivity(int activityNumber) throws OmniException{ + + assert activityNumber != 0 : "There is not activities in the list"; + if (activityNumber > travelActivities.size() || (activityNumber <= 0)) { + throw new OmniException("Travel activity cannot be found"); + } + int indexOfActivity = activityNumber - 1; + TravelActivity markedActivity = travelActivities.get(indexOfActivity); + markedActivity.setActivityStatus(true); + System.out.println("I have checked this activity:"); + System.out.println(markedActivity); + } + + /** + * Unchecks travel activity and sets it to uncompleted + * @param activityNumber The travel activity number on the list + */ + public void uncheckTravelActivity(int activityNumber) throws OmniException{ + assert activityNumber != 0 : "There is not activities in the list"; + if (activityNumber > travelActivities.size() || (activityNumber <= 0)) { + throw new OmniException("Travel activity cannot be found"); + } + int indexOfActivity = activityNumber - 1; + TravelActivity markedActivity = travelActivities.get(indexOfActivity); + markedActivity.setActivityStatus(false); + System.out.println("I have unchecked this activity:"); + System.out.println(markedActivity); + } + + + /** + * 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() || (taskNumber <= 0)) { + 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() || (taskNumber <= 0)) { + 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); + } + + /** + * Updates the date, duration and tag of the travel activity + * @param travelActivityNumber The index of the travel activity + * @param date The new date of the travel activity + * @param duration The new duration of the travel activity + * @param tag The new tag of the travel activity + * @throws OmniException Thrown if the index of the travel activity cannot be found + */ + public void updateTravelActivity(int travelActivityNumber, LocalDate date, String duration, String tag) + throws OmniException{ + if (travelActivityNumber > travelActivities.size() || (travelActivityNumber <= 0)){ + throw new OmniException("Travel activity cannot be found"); + } + int indexOfTravelActivity = travelActivityNumber-1; + TravelActivity updatedTravelActivity = travelActivities.get(indexOfTravelActivity); + String oldTravelActivity = (updatedTravelActivity.toString() + + " (" + updatedTravelActivity.getTag() + ")"); + updatedTravelActivity.setDate(date); + updatedTravelActivity.setDuration(duration); + updatedTravelActivity.setTag(tag); + System.out.println("I have updated this task\nfrom: " + oldTravelActivity + + "\nto: " + updatedTravelActivity + " (" + updatedTravelActivity.getTag() + ")"); + } + + public ArrayList getTravelActivities () { + return travelActivities; + } + + /** + * Find all the tasks with a particular tag and prints them out + * + * @param tag The tag of tasks that the user wants to find + */ + + public void findTag(String tag){ + int foundCounter = 0; + for (TravelActivity travelActivity : travelActivities) { + if (travelActivity.getTag().contains(tag) && + !travelActivity.getTag().isEmpty()) { + foundCounter += 1; + if (foundCounter == 1) { + System.out.println("Here are what you are looking for:"); + } + Ui.printActivity(travelActivity, foundCounter); + } + } + if (foundCounter == 0) { + System.out.println("Sorry I could not find what you are looking for."); + } + } + + /** + * Find all the tasks of a particular type and prints them out + * + * @param type The type of tasks that the user wants to find + */ + + public void findType(String type){ + int foundCounter = 0; + + for (TravelActivity activity: travelActivities){ + if(activity.getClass().getSimpleName().equals(type)){ + foundCounter += 1; + if (foundCounter == 1) { + System.out.println("Here are what you are looking for:"); + } + Ui.printActivity(activity, foundCounter); + } + } + if (foundCounter == 0) { + System.out.println("Sorry I could not find what you are looking for."); + } + } + + + + /** + * Adds expense to travel activity + * @param taskNumber The travel activity number on the list + * @param expense The expense of travel activity + */ + public void expenseActivity(int taskNumber, String expense) throws OmniException { + assert taskNumber != 0 : "There is no tasks in the list"; + if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { + throw new OmniException("Travel activity cannot be found"); + } + int indexOfTask = taskNumber - 1; + TravelActivity task = travelActivities.get(indexOfTask); + task.setExpense(expense); + System.out.println("I have added expense for this task:"); + System.out.println(task + " (" + expense + ")"); + } + + /** + * Removes the expense on a travel activity + * @param taskNumber The travel activity number on the list + */ + public void removeExpense(int taskNumber) throws OmniException { + assert taskNumber != 0 : "There is no task in the list"; + if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { + throw new OmniException("Travel activity cannot be found"); + } + int indexOfTask = taskNumber - 1; + TravelActivity task = travelActivities.get(indexOfTask); + task.removeExpense(); + System.out.println("Expense removed from the task:"); + System.out.println(task); + } + + +} diff --git a/src/main/java/seedu/omnitravel/ui/Ui.java b/src/main/java/seedu/omnitravel/ui/Ui.java index 5f0e51e364..226b463931 100644 --- a/src/main/java/seedu/omnitravel/ui/Ui.java +++ b/src/main/java/seedu/omnitravel/ui/Ui.java @@ -1,8 +1,8 @@ package seedu.omnitravel.ui; -import seedu.omnitravel.error_handlers.OmniException; -import seedu.omnitravel.travel_activity_types.TravelActivity; +import seedu.omnitravel.errorhandlers.OmniException; +import seedu.omnitravel.travelactivitytypes.TravelActivity; import java.util.NoSuchElementException; diff --git a/src/test/java/seedu/omnitravel/OmniTravelTest.java b/src/test/java/seedu/omnitravel/OmniTravelTest.java index f9511f1815..6a1ea0da4e 100644 --- a/src/test/java/seedu/omnitravel/OmniTravelTest.java +++ b/src/test/java/seedu/omnitravel/OmniTravelTest.java @@ -4,9 +4,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import seedu.omnitravel.error_handlers.OmniException; +import seedu.omnitravel.errorhandlers.OmniException; import seedu.omnitravel.parser.Parser; -import seedu.omnitravel.travel_activity_types.*; +import seedu.omnitravel.travelactivitytypes.Food; +import seedu.omnitravel.travelactivitytypes.TravelActivity; +import seedu.omnitravel.travelactivitytypes.TravelActivityList; +import seedu.omnitravel.travelactivitytypes.Accommodation; +import seedu.omnitravel.travelactivitytypes.Landmark; import seedu.omnitravel.ui.Ui; import java.time.LocalDate;