Skip to content

Commit

Permalink
Update code to follow java coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
daryltay415 committed Apr 15, 2024
1 parent 32d14b2 commit 844a6ea
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CheckParameters {
//@@author EugeneChanJiajun
/**
* Checks for all possible input errors that users may make and throws the corresponding exceptions
*
* @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
Expand Down Expand Up @@ -97,6 +98,7 @@ public static void listExceptions(String[] command, String[] input, String line)
//@@author daryltay415
/**
* Checks if a string contains all the words
*
* @param input The input String
* @throws OmniException if duration is invalid
*/
Expand Down Expand Up @@ -132,6 +134,7 @@ public static boolean isNumeric(String str) {

/**
* 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
Expand All @@ -151,14 +154,14 @@ public static boolean isValidExpense(String str) throws OmniException{
/**
* Checks the parameters for the currency exchange command against a list of available currencies.
* It also checks that the parameters are valid
*
* @param command The input given by the user that has been split into an array
* @param line The input given by the user
* @throws OmniException Throws an exception when parameters are invalid
*/
public static void checkCurrencyParameters(String[] command, String line) throws OmniException{
String delimiter = "/";
String[] lineSplit = line.split(delimiter);

if(command.length == 4 && (!isNumeric(command[1].trim()) || Float.parseFloat(command[1].trim()) <= 0)){
throw new OmniException("Please ensure that the amount is a number that is more than 0 and not blank");
} else if(command.length == 4 && command[2].trim().equalsIgnoreCase(command[3].trim())){
Expand All @@ -167,7 +170,6 @@ public static void checkCurrencyParameters(String[] command, String line) throws
throw new OmniException("Please check that your format is correct:\n" +
"change AMOUNT /from CURRENCY /to CURRENCY");
}

}

//@@author EugeneChanJiajun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CurrencyRate {
//@@author daryltay415
/**
* Converts the local currency value to the foreign currency value
*
* @param localCurrency The local currency the user wants to convert
* @param foreignCurrency The foreign currency the user want to convert to
* @param amount The amount of local currency the user wants to change
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/seedu/omnitravel/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public static void removeTagCommand(String[] command, TravelActivityList list) t
//@@author daryltay415
/**
* Handles the case where the update command is given as input
*
* @param line The update command given by the user
* @param list The list of travel activities
* @throws OmniException Thrown if update index, date, duration is not given
Expand Down Expand Up @@ -356,9 +357,7 @@ public static void findCommand(String line, TravelActivityList list) throws Omni
public static void expenseCommand(String line, TravelActivityList list) throws OmniException {
assert line != null && !line.isEmpty() : "Command line should not be null or empty";
assert list != null : "TravelActivityList should not be null";

logger.log(Level.INFO, "Expense command: " + line);

String[] command = line.split(" ");
if (command.length == 3 && CheckParameters.isNumeric(command[1].trim())) {
int listNumber = Integer.parseInt(command[1].trim());
Expand All @@ -383,9 +382,7 @@ public static void expenseCommand(String line, TravelActivityList list) throws O
public static void removeExpenseCommand(String[] command, TravelActivityList list) throws OmniException {
assert command != null && command.length >= 2 : "Command array should not be null or empty";
assert list != null : "TravelActivityList should not be null";

logger.log(Level.INFO, "Remove expense command: " + Arrays.toString(command));

if (command.length == 2 && CheckParameters.isNumeric(command[1].trim())) {
int listNumber = Integer.parseInt(command[1].trim());
list.removeExpense(listNumber);
Expand Down Expand Up @@ -423,16 +420,15 @@ public static void totalExpenseCommand(String line, TravelActivityList list) thr
//@@author ChenKangg
/**
* Handles the case whereby the command is listtags
*
* @param command The command given by the user
* @param list The travel activity list
* @throws OmniException Throws an exception when the command is in an invalid format
*/
public static void listTagsCommand(String[] command, TravelActivityList list) throws OmniException {
assert command != null && command.length >= 1 : "Command array should not be null or empty";
assert list != null : "TravelActivityList should not be null";

logger.log(Level.INFO, "List tags command: " + Arrays.toString(command));

Ui.printLine();
if (command.length == 1) {
logger.log(Level.INFO, "Listing tags");
Expand All @@ -448,6 +444,7 @@ public static void listTagsCommand(String[] command, TravelActivityList list) th
//@@author daryltay415
/**
* Handles the case whereby the command is change
*
* @param line The input given by the user
* @throws OmniException Throws an exception when the parameters are invalid
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/omnitravel/storage/FileSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public FileSave(String path) {

/**
* Reads data from file and loads it into a travel activity list
*
* @param list The travel activity list to load data in to
* @throws FileNotFoundException If the file does not exist
*/
Expand Down Expand Up @@ -88,6 +89,7 @@ public TravelActivity initialiseActivity (String type, String description,

/**
* Saves the travel activity list to the file specified by the file path
*
* @param list The travel activity list to save to the file
* @throws IOException If an I/o error occurs while writing to file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public String toString(){

/**
* Sets the status of the activity to complete or incomplete
*
* @param activityIsDone activity status
*/
public void setActivityStatus(boolean activityIsDone){
Expand All @@ -53,6 +54,7 @@ public void setActivityStatus(boolean activityIsDone){

/**
* Gets the description of the travel activity
*
* @return The description of the travel activity
*/
public String getPlan(){
Expand All @@ -61,6 +63,7 @@ public String getPlan(){

/**
* Gets the status of the travel activity
*
* @return boolean representing if activity is done or not
*/
public boolean getActivityStatus() {
Expand All @@ -69,6 +72,7 @@ public boolean getActivityStatus() {

/**
* Sets the date of the travel activity
*
* @param date the date to be set
*/
public void setDate(LocalDate date){
Expand All @@ -77,6 +81,7 @@ public void setDate(LocalDate date){

/**
* Gets the date of the travel activity.
*
* @return the date of the travel activity
*/
public LocalDate getDate(){
Expand All @@ -85,6 +90,7 @@ public LocalDate getDate(){

/**
* Sets the duration of the travel activity.
*
* @param duration the duration to be set
*/
public void setDuration(String duration){
Expand All @@ -93,6 +99,7 @@ public void setDuration(String duration){

/**
* Gets the duration of the travel activity
*
* @return the duration of the travel activity
*/
public String getDuration(){
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/omnitravel/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void printLine(){

/**
* Prints the OmniException
*
* @param exception The OmniException to be printed
*/
public static void printException(OmniException exception){
Expand All @@ -54,6 +55,7 @@ public static void printException(OmniException exception){

/**
* Prints the NoSuchElement Exception
*
* @param exception The exception to be printed
*/
public static void printNoSuchElementException(NoSuchElementException exception){
Expand All @@ -63,6 +65,7 @@ public static void printNoSuchElementException(NoSuchElementException exception)

/**
* Prints the NumberFormatException
*
* @param exception The exception to be printed
*/
public static void printNumberTooLargeException(NumberFormatException exception) {
Expand Down Expand Up @@ -131,6 +134,7 @@ public static void printInterruptedError(){

/**
* Prints out the activity in a list
*
* @param activity The travel activity
* @param activityIndex The index of the activity
*/
Expand All @@ -144,7 +148,6 @@ public static void printActivity(TravelActivity activity, int activityIndex) {
if(activity.getExpense() != null && !activity.getExpense().isEmpty()){
System.out.print(" (" + activity.getExpense() + ")");
}

System.out.println();
}

Expand Down

0 comments on commit 844a6ea

Please sign in to comment.