Menu Interface
When you launch the application, you’ll see the main menu with all available conversion options:The menu is displayed from
Conversor.eleccionUserMenu() in /workspace/source/src/lad/com/alura/conversormoneda/vista/Conversor.java:4-18Step-by-Step Conversion Process
Step 1
Select a conversion option (1-6) from the menu by entering the corresponding number
Step 2
Enter the amount you want to convert when prompted
Step 3
The application fetches real-time rates from ExchangeRate-API
Step 4
View your conversion result with the target currency code
Conversion Flow
The application processes your conversion request as follows:- Menu Selection: Choose from options 1-6 for different currency pairs
- Amount Input: Enter the value to convert (accepts decimal numbers)
- API Request: The app calls
ConsultaMoneda.obtenerTasa()which fetches current exchange rates - Result Display: Shows the converted amount with the target currency code
- History Tracking: Automatically saves the conversion to your history with timestamp
The conversion logic uses Java’s modern
switch expression with yield statements to map menu options to currency pairs. See ConversorApp.java:50-76Available Conversion Options
Option 1: USD to ARS
Option 1: USD to ARS
Converts US Dollars to Argentine PesosExample:
Option 2: ARS to USD
Option 2: ARS to USD
Converts Argentine Pesos to US DollarsExample:
Option 3: USD to BRL
Option 3: USD to BRL
Converts US Dollars to Brazilian ReaisExample:
Option 4: BRL to USD
Option 4: BRL to USD
Converts Brazilian Reais to US DollarsExample:
Option 5: USD to COP
Option 5: USD to COP
Converts US Dollars to Colombian PesosExample:
Option 6: COP to USD
Option 6: COP to USD
Converts Colombian Pesos to US DollarsExample:
Input Validation
The application handles various input scenarios:- Valid Options (1-6): Proceeds with currency conversion
- History Option (7): Displays conversion history
- Exit Option (8): Closes the application gracefully
- Invalid Options: Displays “Opción no válida. Intente de nuevo.” and returns to menu
Input validation is handled in
ConversorApp.java:43 for conversion options and ConversorApp.java:86-88 for invalid entriesReading Output
After a successful conversion, the output format is:- CONVERTED_AMOUNT: The calculated result as a decimal number
- TARGET_CURRENCY_CODE: Three-letter ISO currency code (USD, ARS, BRL, COP)
Real Example
The result is displayed in
ConversorApp.java:80 and automatically saved to history with a timestamp in ConversorApp.java:83-84Error Handling
If the API connection fails, you’ll see:Error handling is implemented in
ConsultaMoneda.java:31-34