Skip to content

Commit

Permalink
Merge pull request #192 from EugeneChanJiajun/master
Browse files Browse the repository at this point in the history
Bug fixes for PED
  • Loading branch information
daryltay415 committed Apr 6, 2024
2 parents 57f25ec + 4fc6850 commit 396338b
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 47 deletions.
10 changes: 5 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ list via a Command Line Interface**.

6. A GUI similar to the below should appear in a few seconds.



## Features
> 📒 Notes about the command format :
> * The words that are in `UPPER_CASE` represents the parameters that the users are required to input
Expand All @@ -27,10 +29,9 @@ list via a Command Line Interface**.
> 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.
> * Users should not use any `/` into their input descriptions unless using
> * Users should not use any `/` into their input descriptions unless using for input command format

{Give detailed description of each feature}

### Display Commands : `help`
Displays the features of OmniTravel
Expand Down Expand Up @@ -207,12 +208,11 @@ Example of usage:

**Q**: How do I transfer my data to another computer?

**A**: {your answer here}
**A**: To transfer your data to another computer, copy the text file `omni.txt` under the text-ui-test file into the
same location of your other computer to transfer all the activities.

## Command Summary

{Give a 'cheat sheet' of commands here}

* Get activity list `list`
* Get commands `help`
* Exit chatbot `bye`
Expand Down
5 changes: 0 additions & 5 deletions omni.txt

This file was deleted.

17 changes: 10 additions & 7 deletions src/main/java/seedu/omnitravel/errorhandlers/CheckParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ 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
* @param input Line of input that users placed into the chatbot
* @param commandType commandType of the four input commands that add new activities into the list
* @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()) {
public static void addExceptions(String[] input, String commandType, String line) throws OmniException{
String[] command = line.split("/");
if (input.length >= 3 && input[0].substring(commandType.length()).isBlank()) {
throw new OmniException("The description cannot be empty!");
} else if (input.length >= 4 && input[2].isBlank()) {
} else if (input.length >= 3 && input[1].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (input.length >= 4 && input[3].isBlank()) {
} else if (input.length >= 3 && input[2].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if (input.length >= 5 && input[4].isBlank()) {
} else if (input.length >= 4 && input[3].isBlank()) {
throw new OmniException("The tag cannot be empty!");
} else if (input.length < 4 || input[3].contains("/tag")){
} else if (input.length < 3 || input[2].contains("/tag") || !command[1].contains("date")
|| !command[2].contains("duration")){
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");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/omnitravel/omnitravel/OmniTravel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class OmniTravel {
public static void main(String[] args) throws IOException {
Logger logger = Logger.getLogger("Main");
initialiseLogger(logger);
Ui.printGreeting();
FileSave file = new FileSave("omni.txt");
TravelActivityList list = new TravelActivityList();
file.readFile(list);
Ui.printGreeting();
Scanner in = new Scanner(System.in);
while (true) {
try {
Expand Down Expand Up @@ -66,7 +66,8 @@ public static void main(String[] args) throws IOException {
return;
default:
Ui.printLine();
System.out.println("This is not a valid command");
System.out.println("This is not a valid command!");
System.out.println("Use the 'help' command to see the appropriate inputs!");
Ui.printLine();
}
file.saveActivityList(list);
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/seedu/omnitravel/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,24 @@ public static void getList(String[] command, TravelActivityList list) throws Omn
public static void activityCommand(String line, TravelActivityList list) throws OmniException {
Ui.printLine();
String[] command = line.split(" ");
String delimiter = command[0] + "| /date | /duration | /tag ";
String commandType = command[0];
int commandIndex = commandType.length();
String delimiter = " /date | /duration | /tag ";
String[] input = line.split(delimiter);
CheckParameters.addExceptions(input);
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() : "";
CheckParameters.addExceptions(input, commandType, line);
String description = line.substring(commandIndex + 1, line.indexOf("/date")).trim();
LocalDate date = LocalDate.parse(input[1]);
String duration = input[2].trim();
String tag = (line.contains("/tag") && input.length == 4) ? input[3].trim() : "";
TravelActivity activity;
switch (command[0]) {
switch (commandType) {
case "accommodation":
activity = new Accommodation(description, date, duration, tag, "");
System.out.println("I added a new accommodation");
break;
case "food":
activity = new Food(description, date, duration, tag, "");
System.out.println("I added a new restaurant");
System.out.println("I added a new food activity");
break;
case "landmark":
activity = new Landmark(description, date, duration, tag, "");
Expand All @@ -94,13 +96,13 @@ 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[] command = line.split("/date | /duration | /tag ");
logger.log(Level.INFO, command[0] + " // " + command[1]);
CheckParameters.addExceptions(command);
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() : "";
CheckParameters.addExceptions(command, "add", line);
String description = line.substring(4, line.indexOf("/date"));
LocalDate date = LocalDate.parse(command[1]);
String duration = command[2].trim();
String tag = (line.contains("/tag") && command.length == 4) ? command[3].trim() : "";
TravelActivity newActivity = new TravelActivity(description, date, duration, tag, "");
list.addTravelActivity(newActivity);
System.out.println("I added a new travel activity");
Expand Down Expand Up @@ -150,6 +152,7 @@ public static void checkCommand(String[] command, TravelActivityList list) throw
public static void uncheckCommand(String[] command, TravelActivityList list) throws OmniException {
if (command.length == 2 && isNumeric(command[1])){
int listNumber = Integer.parseInt(command[1]);

list.uncheckTravelActivity(listNumber);
} else {
throw new OmniException("Please specify which activity to uncheck");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/omnitravel/storage/FileSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void readFile(TravelActivityList list) {
try {
loadFileContents(list);
} catch (FileNotFoundException e) {
System.out.println("File not found!");
System.out.println("No existing database found! Creating a new save file for you!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public TravelActivity(String description, LocalDate date, String duration, Strin
@Override
public String toString(){
return travelActivity + " :" + date.format(DateTimeFormatter.ofPattern("d MMM yyyy")) + " :" + duration;

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ public void searchKeyword (String activityName) {
* @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);
TravelActivity markedActivity = travelActivities.get(indexOfActivity);
if (!markedActivity.getActivityStatus()) {
markedActivity.setActivityStatus(true);
System.out.println("I have checked this activity:");
System.out.println(markedActivity);
} else {
System.out.println("This activity is already done!");
}
}

/**
Expand All @@ -141,9 +144,13 @@ public void uncheckTravelActivity(int activityNumber) throws OmniException{
}
int indexOfActivity = activityNumber - 1;
TravelActivity markedActivity = travelActivities.get(indexOfActivity);
markedActivity.setActivityStatus(false);
System.out.println("I have unchecked this activity:");
System.out.println(markedActivity);
if (markedActivity.getActivityStatus()) {
markedActivity.setActivityStatus(false);
System.out.println("I have unchecked this activity:");
System.out.println(markedActivity);
} else {
System.out.println("This activity is already unchecked!");
}
}


Expand Down
23 changes: 20 additions & 3 deletions src/main/java/seedu/omnitravel/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public static void printNumberTooLargeException(NumberFormatException exception)
public static void helpCommand(){
printLine();
System.out.println("These are the available commands!");
System.out.println("1. list\n" +
"2. help\n" +
"3. bye\n" +
System.out.println("");
System.out.println("1. list: List out the current list\n" +
"2. help: Get all commands for the chatbot\n" +
"3. bye: Exit the chatbot\n" +
"4. add <travel activity> <date> <duration> <tag>\n" +
"5. accommodation <travel activity> <date> <duration> <tag>\n" +
"6. food <travel activity> <date> <duration> <tag>\n" +
Expand All @@ -79,6 +80,7 @@ public static void helpCommand(){
"16. findtype <type>\n" +
"17. expense <activity number> <expense amount>\n" +
"18. removeexpense <activity number>\n");
printLine();
}

public static void printDateTimeExceptionError(){
Expand All @@ -105,4 +107,19 @@ public static void printActivity(TravelActivity activity, int activityIndex) {
}
System.out.println();
}

public static String[] removeElement(String[] array, int indexToRemove) {
if (indexToRemove < 0 || indexToRemove >= array.length) {
throw new IllegalArgumentException("Index out of bounds");
}
// Create a new array with one less element
String[] newArray = new String[array.length - 1];
// Copy elements from the original array to the new array, excluding the element to remove
for (int i = 0, j = 0; i < array.length; i++) {
if (i != indexToRemove) {
newArray[j++] = array[i];
}
}
return newArray;
}
}
84 changes: 84 additions & 0 deletions src/test/java/seedu/omnitravel/OmniTravelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,90 @@ public void testRemoveExpense() throws OmniException {
assertEquals("visit museum", list.getDescription("visit museum"));
}

@Test
public void testIsNumeric() {
assertTrue(Parser.isNumeric("123"));
assertFalse(Parser.isNumeric("abc"));
}

@Test
public void testGetList() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.getList(new String[]{"list"}, list);
}

@Test
public void testActivityCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.activityCommand("accommodation description /date 2024-04-04 /duration 2 days /tag test", list);
}
/*
// Similar tests for other methods such as addCommand, deleteCommand, checkCommand, uncheckCommand, etc.
@Test
public void testTagCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.tagCommand("tag 1 test", list);
}
@Test
public void testRemoveTagCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.removeTagCommand(new String[]{"removeTag", "1"}, list);
}
@Test
public void testUpdateCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.updateCommand("update 1 /date 2024-04-04 /duration 2 days /tag test", list);
}
@Test
public void testFindTagCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.findTagCommand("findtag test", list);
}
@Test
public void testFindTypeCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.findTypeCommand("findtype test", list);
}
@Test
public void testFindCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.findCommand(new String[]{"find", "test"}, list);
}
/*
@Test
public void testExpenseCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.expenseCommand("expense 1 $50", list);
}
@Test
public void testRemoveExpenseCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.removeExpenseCommand(new String[]{"removeExpense", "1"}, list);
}
@Test
public void testTotalExpenseCommand() throws OmniException {
TravelActivityList list = new TravelActivityList();
// Test with valid input
Parser.totalExpenseCommand("totalexpense", list);
}
*/
}
2 changes: 1 addition & 1 deletion text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
No existing database found! Creating a new save file for you!
____________________________________________________________
____ _ _ _ _____ ____ ____ _ _____ _
/ _ \/ \__/|/ \ /|/ \/__ __\/ __\/ _ \/ \ |\/ __// \
Expand All @@ -7,7 +8,6 @@ ____________________________________________________________
Hello
How may I assist you?
____________________________________________________________
File not found!
____________________________________________________________
Thank you for using Omnitravel
We hope to see you again! Goodbye!
Expand Down

0 comments on commit 396338b

Please sign in to comment.