diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 786eea548f..bad6233473 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -45,7 +45,7 @@ Step 3. The method will then find the travel activity with the corresponding tra of that travel activity. The sequence diagram below shows how an update operation goes through the parser component: -![img.png](img.png) +![img_1.png](img_1.png) #[Proposed] Total Expense feature diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 9ec80b75a9..46ab5b6166 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -2,7 +2,8 @@ ## Introduction -{Give a product intro} +OmniTravel is a software that **allows travellers to store their travel plans and expenses in a +list via a Command Line Interface**. ## Quick Start @@ -12,6 +13,14 @@ 1. Down the latest version of `Duke` from [here](http://link.to/duke). ## Features +> 📒 Notes about the command format : +> * The words that are in `UPPER_CASE` represents the parameters that the users are required to input +> e.g. `delete INDEX`, `INDEX` is a parameter which can be used as `delete 1`. +> * Commands such as `help`, `list` and `bye` do not require additional parameters. Hence, any extra parameters will be ignored. +> e.g. `help 123` will just be intepreted as `help`. +> * Words that are in square brackets such as `[/tag TAG]` indicates that it is +> optional to include in the command. + {Give detailed description of each feature} @@ -24,6 +33,39 @@ Example of usage: `help` +### Adding a general travel activity : `add` +Adds a general travel activity into the travel activity list + +Format: `add DESCRIPTION /date YYYY-MM-DD /duration DURATION [/tag TAG]` + +Examples of usage: +* `add Go to Japan /date 2024-03-14 /duration 7 hours` +* `add Go to Hong Kong /date 2024-08-25 /duration 6 hours /tag with family` + +### Deleting a travel activity : `delete` +Deletes a travel activity from the travel activity list + +Format: `delete INDEX` +* `INDEX` has to be a number that is shown in the list of travel activities + +Examples of usage: `delete 1` + +### Listing all the travel activities : `list` +Shows all the travel activities including their tags and expenses + +Format: `list` + +Examples of usage: `list` + +### Updating a travel activity : `update` +Updates the date, duration and tag of a travel activity + +Format: `update INDEX /date YYYY-MM-DD /duration DURATION [/tag TAG]` +* `INDEX` has to be a number that is shown in the list of travel activities + +Examples of usage: +* `update 1 /date 2019-12-14 /duration 2 hours` +* `update 2 /date 2018-12-12 /duration 3 hours /tag Important` ### Adding a tag: `tag` Adds a new tag to an existing travel activity. @@ -82,6 +124,10 @@ Example of usage: {Give a 'cheat sheet' of commands here} * Get commands `help` +* Add general travel activity `add DESCRIPTION /date YYYY-MM-DD /duration DURATION [/tag TAG]` +* Delete travel activity `delete INDEX` +* List travel activities `list` +* Update travel activity `update INDEX /date YYYY-MM-DD /duration DURATION [/tag TAG]` * Add tag `tag n/ACTIVITY_NUMBER d/TAG_NAME` * Remove tag `untag n/ACTIVITY_NUMBER` * Add expense `expense n/ACTIVITY_NUMBER d/EXPENSE_AMOUNT` diff --git a/omni.txt b/omni.txt index 978dd57540..e9f260d093 100644 --- a/omni.txt +++ b/omni.txt @@ -1,4 +1,4 @@ -general / 0 / germany / 2023-12-12 / 1 week / +general / 1 / germany / 2019-12-12 / now / food / 0 / mala / 2023-12-12 / now / accommodation / 0 / hotel / 2023-12-12 / now / landmark / 0 / statue of liberty / 2023-12-12 / now / diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index 6769bcfc4c..d2903ce936 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -49,19 +49,22 @@ public static void activityCommand(String line, TravelActivityList list) throws String[] command = line.split(" "); String delimiter = command[0] + "| /date | /duration | /tag "; String[] input = line.split(delimiter); - String description = input[1].trim(); - LocalDate date = LocalDate.parse(input[2]); - String duration = input[3].trim(); - String tag = (input.length > 4 && !input[4].isBlank()) ? input[4].trim() : ""; - if (input[1].isBlank()) { + //String tag = (input.length > 4 && !input[4].isBlank()) ? input[4].trim() : ""; + if (input.length >= 4 && input[1].isBlank()) { throw new OmniException("The description of accommodation cannot be empty!"); - } else if (input[2].isBlank()) { + } else if (input.length >= 4 && input[2].isBlank()) { throw new OmniException("The date cannot be empty!"); - } else if (input[3].isBlank()) { + } 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("Wrong format"); } + String description = input[1].trim(); + LocalDate date = LocalDate.parse(input[2]); + String duration = input[3].trim(); + String tag = (line.contains("/tag") && input.length == 5) ? input[4].trim() : ""; TravelActivity activity; switch (command[0]) { case "accommodation": @@ -94,23 +97,26 @@ public static void activityCommand(String line, TravelActivityList list) throws public static void addCommand(String line, TravelActivityList list) throws OmniException{ Ui.printLine(); String[] command = line.split("add | /date | /duration | /tag "); - String description = command[1].trim(); - LocalDate date = LocalDate.parse(command[2]); - String duration = command[3].trim(); - String tag = (command.length > 4 && !command[4].isBlank()) ? command[4].trim() : ""; + //String tag = (command.length > 4 && !command[4].isBlank()) ? command[4].trim() : ""; logger.log(Level.INFO, command[0] + " // " + command[1]); - if (command[1].isBlank()) { + if (command.length >= 4 && command[1].isBlank()) { throw new OmniException("The description of add cannot be empty!"); - } else if(command[2].isBlank()){ + } else if(command.length >= 4 && command[2].isBlank()){ throw new OmniException("The date cannot be empty!"); - } else if (command[3].isBlank()){ + } else if (command.length >= 4 && command[3].isBlank()){ throw new OmniException("The duration cannot be empty!"); + } else if (command.length >= 4 && !command[3].contains("/tag")){ + String description = command[1].trim(); + LocalDate date = LocalDate.parse(command[2]); + String duration = command[3].trim(); + String tag = (line.contains("/tag") && command.length == 5) ? command[4].trim() : ""; + TravelActivity newActivity = new TravelActivity(description, date, duration, tag); + list.addTravelActivity(newActivity); + System.out.println("I added a new travel activity"); + System.out.println(newActivity); + } else { + throw new OmniException("Wrong format"); } - TravelActivity newActivity = new TravelActivity(description, date, duration, tag); - list.addTravelActivity(newActivity); - System.out.println("I added a new travel activity"); - System.out.println(newActivity); - Ui.printLine(); } @@ -216,12 +222,10 @@ public static void updateCommand(String line, TravelActivityList list) throws Om 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 >= 5 && line.contains("/tag")) { - list.updateTravelActivity(Integer.parseInt(command[1]), LocalDate.parse(command[2]), command[3], - command[4]); - } else if (command.length >= 4 && !line.contains("/tag")){ - list.updateTravelActivity(Integer.parseInt(command[1]), LocalDate.parse(command[2]), command[3], - ""); + } else if (command.length >= 4 && !command[3].contains("/tag")) { + String tag = (line.contains("/tag") && command.length == 5)? command[4].trim() : ""; + list.updateTravelActivity(Integer.parseInt(command[1]), LocalDate.parse(command[2]), command[3].trim(), + tag); } else { throw new OmniException("Please check that your update command is in this format: update INDEX " + "/date YYYY-MM-DD /duration DURATION" diff --git a/src/main/java/seedu/duke/TravelActivityList.java b/src/main/java/seedu/duke/TravelActivityList.java index 16bb55934b..2c83597cd5 100644 --- a/src/main/java/seedu/duke/TravelActivityList.java +++ b/src/main/java/seedu/duke/TravelActivityList.java @@ -71,7 +71,7 @@ public int getNoOfTravelActivities(){ */ public void removeTravelActivity(int activityNumber) throws OmniException{ assert activityNumber != 0 :"There is not activities in the list"; - if(activityNumber > travelActivities.size()){ + if(activityNumber > travelActivities.size() || (activityNumber <= 0)){ throw new OmniException("Travel activity cannot be found!"); } int indexOfActivity = activityNumber - 1; @@ -134,7 +134,7 @@ public void searchKeyword (String activityName) { public void checkTravelActivity(int activityNumber) throws OmniException{ assert activityNumber != 0 : "There is not activities in the list"; - if (activityNumber > travelActivities.size()) { + if (activityNumber > travelActivities.size() || (activityNumber <= 0)) { throw new OmniException("Travel activity cannot be found"); } int indexOfActivity = activityNumber - 1; @@ -150,7 +150,7 @@ public void checkTravelActivity(int activityNumber) throws OmniException{ */ public void uncheckTravelActivity(int activityNumber) throws OmniException{ assert activityNumber != 0 : "There is not activities in the list"; - if (activityNumber > travelActivities.size()) { + if (activityNumber > travelActivities.size() || (activityNumber <= 0)) { throw new OmniException("Travel activity cannot be found"); } int indexOfActivity = activityNumber - 1; @@ -168,7 +168,7 @@ public void uncheckTravelActivity(int activityNumber) throws OmniException{ */ public void tagActivity(int taskNumber, String tag) throws OmniException { assert taskNumber != 0 : "There is no tasks in the list"; - if (taskNumber > travelActivities.size()) { + if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { throw new OmniException("Travel activity cannot be found"); } int indexOfTask = taskNumber - 1; @@ -184,7 +184,7 @@ public void tagActivity(int taskNumber, String tag) throws OmniException { */ public void removeTag(int taskNumber) throws OmniException { assert taskNumber != 0 : "There is no task in the list"; - if (taskNumber > travelActivities.size()) { + if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { throw new OmniException("Travel activity cannot be found"); } int indexOfTask = taskNumber - 1; @@ -204,8 +204,7 @@ public void removeTag(int taskNumber) throws OmniException { */ public void updateTravelActivity(int travelActivityNumber, LocalDate date, String duration, String tag) throws OmniException{ - if (travelActivityNumber > travelActivities.size() || (travelActivityNumber==0 && travelActivities.isEmpty()) - || travelActivityNumber < 0){ + if (travelActivityNumber > travelActivities.size() || (travelActivityNumber <= 0)){ throw new OmniException("Travel activity cannot be found"); } int indexOfTravelActivity = travelActivityNumber-1; @@ -318,7 +317,7 @@ public void findType(String type){ */ public void expenseActivity(int taskNumber, String expense) throws OmniException { assert taskNumber != 0 : "There is no tasks in the list"; - if (taskNumber > travelActivities.size()) { + if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { throw new OmniException("Travel activity cannot be found"); } int indexOfTask = taskNumber - 1; @@ -334,7 +333,7 @@ public void expenseActivity(int taskNumber, String expense) throws OmniException */ public void removeExpense(int taskNumber) throws OmniException { assert taskNumber != 0 : "There is no task in the list"; - if (taskNumber > travelActivities.size()) { + if (taskNumber > travelActivities.size() || (taskNumber <= 0)) { throw new OmniException("Travel activity cannot be found"); } int indexOfTask = taskNumber - 1;