Skip to content

Commit

Permalink
Merge branch 'AY2324S2-CS2113-T12-4:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenKangg committed Mar 31, 2024
2 parents d0ebf97 + 5c1ecf6 commit 562cac6
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 226 deletions.
17 changes: 4 additions & 13 deletions omni.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
accommodation / 1 / nus rvrc / 2007-12-12 / 5 years / campus stay
accommodation / 0 / nus pgpr / 2017-10-12 / 5 years / campus stay
accommodation / 0 / nus utr / 2007-09-12 / 5 years / campus stay
landmark / 0 / berlin wall / 2009-12-15 / 5 hours / historic site
landmark / 0 / utown / 2016-08-14 / 10 hours / recreational centre
landmark / 0 / supper stretch / 2021-08-18 / 2 hours / tourist hotspot
food / 0 / utown mala / 2019-06-19 / 2 hours / spicy
food / 0 / pgpr mala / 2012-07-07 / 1 hours / spicy
food / 0 / pgpr waffle / 2006-03-09 / 0.5 hours / non-spicy
general / 0 / esplanade / 2016-03-19 / 3 hours / concert
general / 0 / merlion / 2018-04-07 / 2 hours / sightseeing
general / 0 / chinatown / 2015-02-21 / 5 hours / sightseeing
general / 0 / saizeriya / 2022-12-12 / 2 hours /
general / 0 / germany / 2023-12-12 / 1 week /
food / 0 / mala / 2023-12-12 / now /
accommodation / 0 / hotel / 2023-12-12 / now /
landmark / 0 / statue of liberty / 2023-12-12 / now /
167 changes: 68 additions & 99 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,147 +11,116 @@ public class Duke {
public static void main(String[] args) {
Logger logger = Logger.getLogger("Main");
Ui.printGreeting();
boolean userSaysBye = false;
FileSave file = new FileSave("omni.txt");
TravelActivityList list = new TravelActivityList();
file.readFile(list);
String line;
Scanner in = new Scanner(System.in);
while (!userSaysBye) {
while (true) {
try {
line = in.nextLine();
String line = in.nextLine();
assert line != null :"Input does not exist!";
String[] command = line.split(" ");
logger.log(Level.INFO, command[0]);

switch (command[0].toLowerCase()) {

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

case "add":
Ui.printLine();
Parser.addCommand(line, list);
Ui.printLine();
break;

case "accommodation":
Ui.printLine();
Parser.activityCommand(line, list);
Ui.printLine();
break;

case "food":
Ui.printLine();
Parser.activityCommand(line, list);
Ui.printLine();
break;

case "landmark":
Ui.printLine();
Parser.activityCommand(line, list);
Ui.printLine();
break;

case "delete":
Ui.printLine();
Parser.deleteCommand(command, list);
Ui.printLine();
break;

case "check":
Ui.printLine();
Parser.checkCommand(command, list);
Ui.printLine();
break;

case "uncheck":
Ui.printLine();
Parser.uncheckCommand(command, list);
Ui.printLine();
break;

case "find":
Ui.printLine();
Parser.findCommand(command, list);
Ui.printLine();
break;

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

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

case "help":
Ui.printLine();
Ui.helpCommand();
Ui.printLine();
break;

case "bye":
Ui.printBye();
userSaysBye = true;
break;

case "update":
Ui.printLine();
Parser.updateCommand(line, list);
Ui.printLine();
break;

case "findtag":
Ui.printLine();
Parser.findTagCommand(line, list);
Ui.printLine();
break;

case "findtype":
Ui.printLine();
Parser.findTypeCommand(line, list);
Ui.printLine();
break;

case "expense":
Ui.printLine();
Parser.expenseCommand(line, list);
Ui.printLine();
break;

case "removeexpense":
Ui.printLine();
Parser.removeExpenseCommand(command, list);
Ui.printLine();
invokeCommand(command, line, list);
break;

case "help":
Ui.helpCommand();
break;
case "bye":
Ui.printBye();
return;
default:
Ui.printLine();
System.out.println("This is not a valid command");
Ui.printLine();
}
file.saveActivityList(list);
} catch (OmniException exception){
Ui.printException(exception);
} catch (NoSuchElementException exception){
Ui.printNoSuchElementException(exception);
} catch (NumberFormatException exception) {
Ui.printNumberTooLargeException(exception);
} catch (DateTimeException exception){
Ui.printDateTimeExceptionError();
} catch (IOException exception){
Ui.printSavingError();
} catch (OmniException | NoSuchElementException | NumberFormatException | DateTimeException
| IOException exception) {
handleException(exception);
}
}
}
private static void invokeCommand(String[] command,
String line, TravelActivityList list) throws OmniException, IOException {
Ui.printLine();
switch (command[0].toLowerCase()) {
case "delete":
Parser.deleteCommand(command, list);
break;
case "check":
Parser.checkCommand(command, list);
break;
case "uncheck":
Parser.uncheckCommand(command, list);
break;
case "find":
Parser.findCommand(command, list);
break;
case "tag":
Parser.tagCommand(line, list);
break;
case "untag":
Parser.removeTagCommand(command, list);
break;
case "update":
Parser.updateCommand(line, list);
break;
case "findtag":
Parser.findTagCommand(line, list);
break;
case "findtype":
Parser.findTypeCommand(line, list);
break;
case "expense":
Parser.expenseCommand(line, list);
break;
case "removeexpense":
Parser.removeExpenseCommand(command, list);
break;
default:
throw new OmniException("Invalid command");
}
Ui.printLine();
}

private 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();
}
}
}


Expand Down
59 changes: 15 additions & 44 deletions src/main/java/seedu/duke/FileSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,32 @@ public void loadFileContents(TravelActivityList list) throws FileNotFoundExcepti
Scanner s = new Scanner(f);
while (s.hasNext()){
String[] line = s.nextLine().split(" / ");
switch (line[0].toLowerCase()){
String type = line[0].toLowerCase();
String description = line[2];
LocalDate date = LocalDate.parse(line[3]);
String duration = line[4];
String tag = (line.length == 6) ? line[5].trim() : "";
TravelActivity activity;
switch (type) {
case "accommodation":
TravelActivity accommodation;
if (line.length == 6) {
accommodation = new Accommodation(line[2], LocalDate.parse(line[3]), line[4], line[5].trim());
} else {
accommodation = new Accommodation(line[2], LocalDate.parse(line[3]), line[4], "");
}
list.addTravelActivity(accommodation);
if(line[1].equals("1")){
accommodation.setActivityStatus(true);
}
activity = new Accommodation(description, date, duration, tag);
break;
case "food":
TravelActivity food;
if (line.length == 6) {
food = new Food(line[2], LocalDate.parse(line[3]), line[4], line[5].trim());
} else {
food = new Food(line[2], LocalDate.parse(line[3]), line[4], "");
}

list.addTravelActivity(food);
if(line[1].equals("1")){
food.setActivityStatus(true);
}
activity = new Food(description, date, duration, tag);
break;
case "landmark":
TravelActivity landmark;
if (line.length == 6) {
landmark = new Landmark(line[2], LocalDate.parse(line[3]), line[4], line[5].trim());
} else {
landmark = new Landmark(line[2], LocalDate.parse(line[3]), line[4], "");
}
list.addTravelActivity(landmark);
if(line[1].equals("1")){
landmark.setActivityStatus(true);
}
activity = new Landmark(description, date, duration, tag);
break;
case "general":
TravelActivity newActivity;
if (line.length == 6) {
newActivity = new TravelActivity(line[2], LocalDate.parse(line[3]),
line[4], line[5].trim());
} else {
newActivity = new TravelActivity(line[2], LocalDate.parse(line[3]),
line[4], "");
}
list.addTravelActivity(newActivity);
if(line[1].equals("1")){
newActivity.setActivityStatus(true);
}
activity = new TravelActivity(description, date, duration, tag);
break;
default:
throw new FileNotFoundException("File is corrupted or has invalid format");
}
list.addTravelActivity(activity);
if (line[1].equals("1")) {
activity.setActivityStatus(true);
}
}
}

Expand Down
Loading

0 comments on commit 562cac6

Please sign in to comment.