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 6a6632a + e548ca5 commit 4bece48
Show file tree
Hide file tree
Showing 11 changed files with 351 additions and 95 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 @@ -238,12 +239,11 @@ Examples of usage: `findlocation Singapore`

**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
9 changes: 4 additions & 5 deletions omni.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
food / 0 / takoyaki / 2019-12-12 / 2 hours / / $50
landmark / 0 / Eiffel Tower / 2024-12-12 / 2 hour / / 40
food / 0 / prata / 2024-12-12 / 1 hour / /
accommodation / 0 / hotel / 2024-12-12 / one night / / 100
general / 0 / visit Paris / 2024-12-12 / 2 weeks / leisure /
general / 0 / go to paris / 2024-12-12 / 2 hours / hello / $50
food / 0 / food / 2024-12-12 / now / /
food / 0 / food / 2024-12-12 / 2 hours / / $30
general / 0 / hello world / 2040-12-12 / 2 hours / your mom /
73 changes: 65 additions & 8 deletions src/main/java/seedu/omnitravel/errorhandlers/CheckParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@
import java.time.DateTimeException;
import java.util.NoSuchElementException;

import static seedu.omnitravel.parser.Parser.isNumeric;


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 All @@ -53,6 +59,57 @@ public static void updateExceptions(String[] command) throws OmniException {
}
}

/**
* Checks if a string contains all the words
* @param input The input String
*/
public static void containsWords(String input) throws OmniException{
String[] inputSplit = input.split(" ");
if (inputSplit.length == 2){
String[] durationKeyWords = {"day", "month", "year", "hour", "minute", "second"};
for(String word:durationKeyWords){
if(input.contains(word)){
return;
}
}
}
throw new OmniException("Your duration is invalid. Please input in terms of \"1 " +
"day, month, year, hour, minutue or second\"");
}

/**
* Checks if the string is a number
*
* @param str The string that is to be defined as a number or sentence
* @return true or false
*/
public static boolean isNumeric(String str) {
try {
Double.parseDouble(str);
return true;
} catch(NumberFormatException e){
return false;
}
}

/**
* Checks if the expense given is valid
* @param str
* @return True or false
* @throws OmniException Throws an exception when the expense given is less than $0
*/
public static boolean isValidExpense(String str) throws OmniException{
if(isNumeric(str)){
int expense = Integer.parseInt(str);
if(expense <= 0){
throw new OmniException("Your expense cannot be less than $0");
}
} else{
return false;
}
return true;
}

/**
* Checks for all format errors in the user input and throes the correct exceptions
*
Expand Down
10 changes: 7 additions & 3 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 All @@ -36,6 +36,9 @@ public static void main(String[] args) throws IOException {
case "list":
Parser.getList(command, list);
break;
case "listtags":
Parser.listTagsCommand(command, list);
break;
case "add":
Parser.addCommand(line, list);
break;
Expand Down Expand Up @@ -70,7 +73,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 Expand Up @@ -103,7 +107,7 @@ private static void invokeCommand(String[] command,
Parser.uncheckCommand(command, list);
break;
case "find":
Parser.findCommand(command, list);
Parser.findCommand(line, list);
break;
case "tag":
Parser.tagCommand(line, list);
Expand Down
Loading

0 comments on commit 4bece48

Please sign in to comment.