Enum Class Currency

All Implemented Interfaces:
Serializable, Comparable<Currency>, Constable

public enum Currency extends Enum<Currency>
The Currency enum represents different currencies and provides methods for converting between them.

Includes methods for converting an amount from the currency to Euro and vice versa and a method to find a Currency by its display string.

  • Enum Constant Details

    • EURO

      public static final Currency EURO
      The Euro currency, last updated on 2024-12-01.
    • US_DOLLAR

      public static final Currency US_DOLLAR
      The US Dollar currency, last updated on 2024-12-01.
    • BRITISH_POUND

      public static final Currency BRITISH_POUND
      The British Pound currency, last updated on 2024-12-01.
  • Method Details

    • values

      public static Currency[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Currency valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • convertToDisplayString

      public String convertToDisplayString()
      Returns a user-friendly display string for the currency.
      Returns:
      the display string
    • getSymbol

      public String getSymbol()
      Returns the currency symbol.
      Returns:
      the currency symbol as a string
    • fromDisplayString

      public static Currency fromDisplayString(String displayString)
      Finds a Currency by its display string.
      Parameters:
      displayString - the display string to search for
      Returns:
      the corresponding Currency
      Throws:
      IllegalArgumentException - if no match is found
    • convertToEuro

      public double convertToEuro(double amount)
      Converts an amount from this currency to Euro, rounding to two decimal places.
      Parameters:
      amount - the amount to convert
      Returns:
      the amount in Euro
    • convertFromEuro

      public double convertFromEuro(double amount)
      Converts an amount from Euro to this currency, rounding to two decimal places.
      Parameters:
      amount - the amount to convert
      Returns:
      the amount in this currency