WeatherForecast / IForecast.java
IForecast.java
Raw
/**
 * This interface defines getter methods for each weather forecast's properties. Each forecast
 * object is comparable (by date + time) to other forecast objects.
 * 
 * @author Tommy F
 */
public interface IForecast extends Comparable<IForecast> {

  /**
   * Returns a string with the date of the start of this forecast.
   * 
   * @return A string in the format "October 18, 2022"
   */
  String getDate();

  /**
   * Returns a string with the condensed date of the start of this forecast.
   * 
   * @return A string in the format "Oct 18, 2022"
   */
  String getShortDate();

  /**
   * Returns a string with the start time of this forecast.
   * 
   * @param format  The clock format to return the time in, '1' for 12hr or '2' for 24hr
   * @param minutes Input true to include the minutes following the hour (9 vs 9:00)
   * @param marker  Input true to include the 'AM' or 'PM' marker after the time
   * @return A string in the requested format, max length 8 characters
   * @throws IllegalArgumentException If given an unknown format character
   */
  String getStartTime(char format, boolean minutes, boolean marker) throws IllegalArgumentException;

  /**
   * Returns a string with the end time of this forecast.
   * 
   * @param format  The clock format to return the time in, '1' for 12hr or '2' for 24hr
   * @param minutes Input true to include the minutes following the hour (9 vs 9:00)
   * @param marker  Input true to include the 'AM' or 'PM' marker after the time
   * @return A string in the requested format, max length 8 characters
   * @throws IllegalArgumentException If given an unknown format character
   */
  String getEndTime(char format, boolean minutes, boolean marker) throws IllegalArgumentException;

  /**
   * Returns the time range of this forecast as an integer. Intended for use in compareTo(), but you
   * can use it if you need a specialized time format other than the getters provided. Integer is
   * returned in the format "YYYYMMDDHH". Example: 2022101915. (10/19/2022 15:00 - 18:00)
   * 
   * @return An integer representing the date and time of this forecast
   */
  int getTimeCode();

  /**
   * Returns an short description of the weather condition, such as "clear sky" or "light rain".
   * 
   * @return A short description of the weather condition
   */
  String getDescription();

  /**
   * Returns the average temperature for this forecast.
   * 
   * @param unit The unit to return temperature in, 'f' or 'c'
   * @return The average temperature for this forecast in the specified unit, rounded to one decimal
   * @throws IllegalArgumentException If given an unknown format character
   */
  double getAverageTemp(char unit) throws IllegalArgumentException;

  /**
   * Returns the maximum temperature for this forecast.
   * 
   * @param unit The unit to return temperature in, 'f' or 'c'
   * @return The maximum temperature for this forecast in the specified unit, rounded to one decimal
   * @throws IllegalArgumentException If given an unknown format character
   */
  double getMaxTemp(char unit) throws IllegalArgumentException;

  /**
   * Returns the minimum temperature for this forecast.
   * 
   * @param unit The unit to return temperature in, 'f' or 'c'
   * @return The minimum temperature for this forecast in the specified unit, rounded to one decimal
   * @throws IllegalArgumentException If given an unknown format character
   */
  double getMinTemp(char unit) throws IllegalArgumentException;

  /**
   * Returns the humidity percentage for this forecast (1 - 100).
   * 
   * @return The humidity percentage for this forecast
   */
  int getHumidityPercentage();

  /**
   * Returns a string of the approximate wind direction (N, NE, E, SE, S, SW, W, or NW).
   * 
   * @return A string of the wind direction
   */
  String getWindDirection();

  /**
   * Returns the wind speed for this forecast.
   * 
   * @param unit The unit to return wind speed in, 'i' for imperial MPH, 'm' for metric m/s
   * @return The wind speed for this forecast in the selected units, rounded to one decimal
   * @throws IllegalArgumentException If given an unknown format character
   */
  double getWindSpeed(char unit) throws IllegalArgumentException;
}