diff --git a/src/main/java/seedu/omnitravel/storage/FileSave.java b/src/main/java/seedu/omnitravel/storage/FileSave.java index 4a713c5d5f..f4bd1cc7e9 100644 --- a/src/main/java/seedu/omnitravel/storage/FileSave.java +++ b/src/main/java/seedu/omnitravel/storage/FileSave.java @@ -33,23 +33,7 @@ public void loadFileContents(TravelActivityList list) throws FileNotFoundExcepti String duration = line[4]; String tag = line.length >= 6 ? line[5].trim() : ""; String expense = line.length >= 7 ? line[6].trim() : ""; - TravelActivity activity; - switch (type) { - case "accommodation": - activity = new Accommodation(description, date, duration, tag, expense); - break; - case "food": - activity = new Food(description, date, duration, tag, expense); - break; - case "landmark": - activity = new Landmark(description, date, duration, tag, expense); - break; - case "general": - activity = new TravelActivity(description, date, duration, tag, expense); - break; - default: - throw new FileNotFoundException("File is corrupted or has invalid format"); - } + TravelActivity activity = initialiseActivity (type, description, date, duration, tag, expense); list.addTravelActivity(activity); if (line[1].equals("1")) { activity.setActivityStatus(true); @@ -57,6 +41,28 @@ public void loadFileContents(TravelActivityList list) throws FileNotFoundExcepti } } + public TravelActivity initialiseActivity (String type, String description, + LocalDate date, String duration, String tag, String expense) throws FileNotFoundException { + TravelActivity activity; + switch (type) { + case "accommodation": + activity = new Accommodation(description, date, duration, tag, expense); + break; + case "food": + activity = new Food(description, date, duration, tag, expense); + break; + case "landmark": + activity = new Landmark(description, date, duration, tag, expense); + break; + case "general": + activity = new TravelActivity(description, date, duration, tag, expense); + break; + default: + throw new FileNotFoundException("File is corrupted or has invalid format"); + } + return activity; + } + public void saveActivityList(TravelActivityList list) throws IOException { logger.log(Level.INFO, "saveActivityList"); FileWriter fw = new FileWriter(filePath);