Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ChenKangg/tp
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenKangg committed Apr 7, 2024
2 parents 0c73c86 + 62dfcba commit 07fccd5
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
34 changes: 34 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,37 @@ Example of usage:
`totalexpense /type food`
`totalexpense`

### Adding a location: `location`
Adds a location to an existing travel activity.

Format: `location INDEX LOCATION`

* The `INDEX` must be a valid activity index
*
Example of usage:

`location 3 Singapore`

### Removing an expense amount: `removelocation`
Removes a location to an existing travel activity.

Format: `removelocation INDEX`

* The `INDEX` must be a valid activity index.

Example of usage:

`removelocation 3`

### Find activity from the list using activity location: `findlocation`

Find an activity based on their location. All activities with the given location will be listed out.

Format: `findlocation LOCATION`
* `LOCATION` has to match the activity location exactly to find the activity

Examples of usage: `findlocation Singapore`

## FAQ

**Q**: How do I transfer my data to another computer?
Expand Down Expand Up @@ -232,3 +263,6 @@ Example of usage:
* Add expense `expense INDEX EXPENSE`
* Remove expense `removeexpense INDEX`
* Total expense `totalexpense [/type TYPE]`
* Add location `location INDEX LOCATION`
* Remove location `removelocation INDEX`
* Find location `findlocation LOCATION`
7 changes: 6 additions & 1 deletion src/main/java/seedu/omnitravel/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package seedu.omnitravel.parser;
import seedu.omnitravel.travelactivitytypes.*;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.Entertainment;
import seedu.omnitravel.travelactivitytypes.TravelActivity;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.errorhandlers.CheckParameters;
import seedu.omnitravel.errorhandlers.OmniException;
import seedu.omnitravel.ui.Ui;
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/seedu/omnitravel/storage/FileSave.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.omnitravel.storage;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.Entertainment;
import seedu.omnitravel.travelactivitytypes.TravelActivity;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;

import java.io.FileWriter;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -32,20 +33,24 @@ public void loadFileContents(TravelActivityList list) throws FileNotFoundExcepti
LocalDate date = LocalDate.parse(line[3]);
String duration = line[4];
String tag = line.length >= 6 ? line[5].trim() : "";
String expense = line.length >= 7 ? line[6].trim() : "";
String location = line.length >= 7 ? line[6].trim() : "";
String expense = line.length >= 8 ? line[7].trim() : "";
TravelActivity activity;
switch (type) {
case "accommodation":
activity = new Accommodation(description, date, duration, tag, expense);
activity = new Accommodation(description, date, duration, tag, location, expense);
break;
case "food":
activity = new Food(description, date, duration, tag, expense);
activity = new Food(description, date, duration, tag, location, expense);
break;
case "entertainment":
activity = new Entertainment(description, date, duration, tag, location, expense);
break;
case "landmark":
activity = new Landmark(description, date, duration, tag, expense);
activity = new Landmark(description, date, duration, tag, location, expense);
break;
case "general":
activity = new TravelActivity(description, date, duration, tag, expense);
activity = new TravelActivity(description, date, duration, tag, location, expense);
break;
default:
throw new FileNotFoundException("File is corrupted or has invalid format");
Expand Down
46 changes: 43 additions & 3 deletions src/test/java/seedu/omnitravel/OmniTravelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import org.junit.jupiter.api.Test;
import seedu.omnitravel.errorhandlers.OmniException;
import seedu.omnitravel.parser.Parser;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.Entertainment;
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;
Expand Down Expand Up @@ -50,6 +51,12 @@ class OmniTravelTest {
"2 hours", "sightseeing", "Singapore", "");
TravelActivity travelActivityNew3 = new TravelActivity("chinatown", LocalDate.parse("2015-02-21"),
"5 hours", "sightseeing","Singapore", "");
Entertainment entertainmentNew1 = new Entertainment("watch movie", LocalDate.parse("2020-01-19"),
"2 hours", "media", "Singapore", "");
Entertainment entertainmentNew2 = new Entertainment("hiking", LocalDate.parse("2021-10-25"),
"6 hours", "outdoors", "Singapore", "");
Entertainment entertainmentNew3 = new Entertainment("food tour", LocalDate.parse("2019-06-14"),
"3 hours", "culinary", "Singapore", "");

private final PrintStream printedText = System.out;
private final ByteArrayOutputStream capturedOutputStream = new ByteArrayOutputStream();
Expand Down Expand Up @@ -206,6 +213,9 @@ public void findTagTest () {
travelActivityListNew.addTravelActivity(travelActivityNew1);
travelActivityListNew.addTravelActivity(travelActivityNew2);
travelActivityListNew.addTravelActivity(travelActivityNew3);
travelActivityListNew.addTravelActivity(entertainmentNew1);
travelActivityListNew.addTravelActivity(entertainmentNew2);
travelActivityListNew.addTravelActivity(entertainmentNew3);

String findExpectedOutput2 = "Here are what you are looking for:" + System.lineSeparator() +
"[ ] 1. merlion :7 Apr 2018 :2 hours (sightseeing)" + System.lineSeparator() +
Expand Down Expand Up @@ -235,6 +245,9 @@ public void findTypeTest () {
travelActivityListNew.addTravelActivity(travelActivityNew1);
travelActivityListNew.addTravelActivity(travelActivityNew2);
travelActivityListNew.addTravelActivity(travelActivityNew3);
travelActivityListNew.addTravelActivity(entertainmentNew1);
travelActivityListNew.addTravelActivity(entertainmentNew2);
travelActivityListNew.addTravelActivity(entertainmentNew3);

String findExpectedOutput3 = "Here are what you are looking for:" + System.lineSeparator() +
"[ ] 1. Accommodation: nus rvrc :12 Dec 2007 :5 years (campus stay)" + System.lineSeparator() +
Expand Down Expand Up @@ -284,7 +297,7 @@ public void testUpdateActivity() throws OmniException{
TravelActivityList travelActivityList = new TravelActivityList();
TravelActivity travelActivity1 = new TravelActivity("Go Paris",
LocalDate.parse("2019-02-10"),"2hours", "Sightseeing",
"Singapore","$40");
"France","$40");
travelActivityList.addTravelActivity(travelActivity1);
assertEquals("10 Feb 2019",
travelActivity1.getDate().format(DateTimeFormatter.ofPattern("dd MMM yyyy")));
Expand Down Expand Up @@ -325,7 +338,34 @@ public void testRemoveExpense() throws OmniException {
assertEquals("visit museum", list.getDescription("visit museum"));
}

@Test
public void testLocation() throws OmniException {
TravelActivityList list = new TravelActivityList();
list.addTravelActivity(new TravelActivity("visit museum",
LocalDate.parse("2019-05-12"),"2hours", "Sightseeing",
"Museum", "$50"));
assertEquals("visit museum", list.getDescription("visit museum"));
// Adding a location an existing task
list.locationActivity(1, "Singapore");
TravelActivity travelActivity = list.getTravelActivities().get(0);
assertEquals("Singapore", travelActivity.getLocation());
}

@Test
public void testRemoveLocation() throws OmniException {
TravelActivityList list = new TravelActivityList();
list.addTravelActivity(new TravelActivity("visit museum",
LocalDate.parse("2019-05-12"),"2hours", "Sightseeing",
"Singapore", "$100"));
assertEquals("visit museum", list.getDescription("visit museum"));
// Adding a location an existing task
list.locationActivity(1, "Singapore");
TravelActivity travelActivity = list.getTravelActivities().get(0);
assertEquals("Singapore", travelActivity.getLocation());
// Remove an existing location
list.removeLocation(1);
assertEquals("visit museum", list.getDescription("visit museum"));
}



Expand Down

0 comments on commit 07fccd5

Please sign in to comment.