Enum Class Currency
- All Implemented Interfaces:
Serializable
,Comparable<Currency>
,Constable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe British Pound currency, last updated on 2024-12-01.The Euro currency, last updated on 2024-12-01.The US Dollar currency, last updated on 2024-12-01. -
Method Summary
Modifier and TypeMethodDescriptiondouble
convertFromEuro
(double amount) Converts an amount from Euro to this currency, rounding to two decimal places.Returns a user-friendly display string for the currency.double
convertToEuro
(double amount) Converts an amount from this currency to Euro, rounding to two decimal places.static Currency
fromDisplayString
(String displayString) Finds a Currency by its display string.Returns the currency symbol.static Currency
Returns the enum constant of this class with the specified name.static Currency[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
EURO
The Euro currency, last updated on 2024-12-01. -
US_DOLLAR
The US Dollar currency, last updated on 2024-12-01. -
BRITISH_POUND
The British Pound currency, last updated on 2024-12-01.
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
convertToDisplayString
Returns a user-friendly display string for the currency.- Returns:
- the display string
-
getSymbol
-
fromDisplayString
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
-