Skip to content

Commit

Permalink
Merge pull request #121 from daryltay415/master
Browse files Browse the repository at this point in the history
Add packages
  • Loading branch information
EugeneChanJiajun committed Apr 1, 2024
2 parents 672fce8 + cb17222 commit d16dc27
Show file tree
Hide file tree
Showing 13 changed files with 670 additions and 627 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ test {
}

application {
mainClass.set("seedu.duke.Duke")
mainClass.set("seedu.omnitravel.omnitravel.OmniTravel")
}

shadowJar {
archiveBaseName.set("duke")
archiveBaseName.set("omnitravel")
archiveClassifier.set("")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
package seedu.duke;

import java.io.IOException;
import java.time.DateTimeException;
import java.util.NoSuchElementException;

import static seedu.duke.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
* @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()) {
throw new OmniException("The description cannot be empty!");
} else if (input.length >= 4 && input[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (input.length >= 4 && input[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if (input.length >= 5 && input[4].isBlank()) {
throw new OmniException("The tag cannot be empty!");
} else if (input.length < 4 || input[3].contains("/tag")){
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");
}
}

/**
* Checks for all possible input errors that users may make when updating and throws the corresponding exceptions
*
* @param command Command array that users placed into the chatbot
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void updateExceptions(String[] command) throws OmniException {
if (command.length >= 4 && (command[1].isBlank() || !isNumeric(command[1]))) {
throw new OmniException("The update index cannot be empty or non numerical!");
} else if (command.length >= 4 && command[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (command.length >= 4 && command[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if(command.length >= 5 && command[4].isBlank()){
throw new OmniException("The tag cannot be empty!");
} else if (command.length >= 4 && !command[3].contains("/tag")) {
throw new OmniException("Please check that your update command is in this format: update INDEX " +
"/date YYYY-MM-DD /duration DURATION"
+ " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

/**
* Checks for all format errors in the user input and throes the correct exceptions
*
* @param exception Exception thrown
*/
public 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();
}
}
}
package seedu.omnitravel.errorhandlers;

import seedu.omnitravel.ui.Ui;

import java.io.IOException;
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
* @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()) {
throw new OmniException("The description cannot be empty!");
} else if (input.length >= 4 && input[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (input.length >= 4 && input[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if (input.length >= 5 && input[4].isBlank()) {
throw new OmniException("The tag cannot be empty!");
} else if (input.length < 4 || input[3].contains("/tag")){
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");
}
}

/**
* Checks for all possible input errors that users may make when updating and throws the corresponding exceptions
*
* @param command Command array that users placed into the chatbot
* @throws OmniException when any of the corresponding input format is wrong
*/
public static void updateExceptions(String[] command) throws OmniException {
if (command.length >= 4 && (command[1].isBlank() || !isNumeric(command[1]))) {
throw new OmniException("The update index cannot be empty or non numerical!");
} else if (command.length >= 4 && command[2].isBlank()) {
throw new OmniException("The date cannot be empty!");
} else if (command.length >= 4 && command[3].isBlank()) {
throw new OmniException("The duration cannot be empty!");
} else if(command.length >= 5 && command[4].isBlank()){
throw new OmniException("The tag cannot be empty!");
} else if (command.length >= 4 && !command[3].contains("/tag")) {
throw new OmniException("Please check that your update command is in this format: update INDEX " +
"/date YYYY-MM-DD /duration DURATION"
+ " or update INDEX /date YYYY-MM-DD /duration DURATION /tag TAG");
}
}

/**
* Checks for all format errors in the user input and throes the correct exceptions
*
* @param exception Exception thrown
*/
public 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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.duke;

public class OmniException extends Exception {
public OmniException(String errorMessage){
super(errorMessage);
}
}
package seedu.omnitravel.errorhandlers;

public class OmniException extends Exception {
public OmniException(String errorMessage){
super(errorMessage);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package seedu.duke;
package seedu.omnitravel.omnitravel;
import seedu.omnitravel.parser.Parser;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.ui.Ui;
import seedu.omnitravel.errorhandlers.CheckParameters;
import seedu.omnitravel.errorhandlers.OmniException;
import seedu.omnitravel.storage.FileSave;

import java.io.IOException;
import java.time.DateTimeException;
import java.util.NoSuchElementException;
Expand All @@ -9,7 +16,7 @@
import java.util.logging.SimpleFormatter;
import java.util.logging.LogManager;

public class Duke {
public class OmniTravel {

public static void main(String[] args) throws IOException {
Logger logger = Logger.getLogger("Main");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package seedu.duke;
package seedu.omnitravel.parser;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.errorhandlers.CheckParameters;
import seedu.omnitravel.errorhandlers.OmniException;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.TravelActivity;
import seedu.omnitravel.ui.Ui;

import java.time.LocalDate;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -26,7 +35,7 @@ public static boolean isNumeric(String str) {
*
* @param list List of travel activities.
*/
public static void getList(String[] command, TravelActivityList list) throws OmniException{
public static void getList(String[] command, TravelActivityList list) throws OmniException {
Ui.printLine();
if (command.length == 1) {
System.out.println("Here are the travel activities in your list:");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package seedu.duke;
package seedu.omnitravel.storage;
import seedu.omnitravel.travelactivitytypes.TravelActivityList;
import seedu.omnitravel.travelactivitytypes.Accommodation;
import seedu.omnitravel.travelactivitytypes.Food;
import seedu.omnitravel.travelactivitytypes.Landmark;
import seedu.omnitravel.travelactivitytypes.TravelActivity;

import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package seedu.duke;

import java.time.LocalDate;

public class Accommodation extends TravelActivity {
private LocalDate date;
private String duration;

public Accommodation(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Accommodation: " + super.toString();
}

}
package seedu.omnitravel.travelactivitytypes;

import java.time.LocalDate;

public class Accommodation extends TravelActivity {
private LocalDate date;
private String duration;

public Accommodation(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Accommodation: " + super.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package seedu.duke;

import java.time.LocalDate;

public class Food extends TravelActivity {
public Food(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Food: " + super.toString();
}
}
package seedu.omnitravel.travelactivitytypes;

import java.time.LocalDate;

public class Food extends TravelActivity {
public Food(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}

@Override
public String toString(){
return "Food: " + super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package seedu.duke;

import java.time.LocalDate;

public class Landmark extends TravelActivity {
public Landmark(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}
@Override
public String toString(){
return "Landmark: " + super.toString();
}
}
package seedu.omnitravel.travelactivitytypes;

import java.time.LocalDate;

public class Landmark extends TravelActivity {
public Landmark(String line, LocalDate date, String duration, String tag, String expense){
super(line, date, duration, tag, expense);
}
@Override
public String toString(){
return "Landmark: " + super.toString();
}
}
Loading

0 comments on commit d16dc27

Please sign in to comment.