Skip to main content
The Currency Converter automatically tracks all your conversions in a history log, allowing you to review past transactions with detailed timestamps.

Accessing History

To view your conversion history:
  1. From the main menu, select option 7
  2. The application displays all conversions made during the current session
  3. Press any key to return to the main menu
7) Historial de conversiones
History viewing is implemented in ConversorApp.java:32-41 and uses Java streams with lambda expressions for efficient display

History Format

Each conversion record follows this format:
[DD-MM-YYYY HH:mm:ss] AMOUNT BASE_CURRENCY =>> RESULT TARGET_CURRENCY

Format Components

Timestamp

Date and time when the conversion was performed, formatted as day-month-year with 24-hour time

Original Amount

The amount you entered for conversion

Base Currency

The currency you converted from (e.g., USD, ARS, BRL, COP)

Result

The converted amount in the target currency

Example History Output

With Conversions

When you have performed conversions, the history displays:
--- HISTORIAL DE CONVERSIONES ---
[05-03-2026 14:23:45] 100.0 USD =>> 35000.0 ARS
[05-03-2026 14:25:12] 50.0 USD =>> 247.75 BRL
[05-03-2026 14:27:33] 200.0 USD =>> 760000.0 COP
[05-03-2026 14:29:01] 500.0 ARS =>> 1.43 USD
---------------------------------
This shows four conversions performed during the session, each with its precise timestamp.

Empty History

If no conversions have been performed yet, you’ll see:
--- HISTORIAL DE CONVERSIONES ---
No hay conversiones recientes.
---------------------------------
Empty history check is handled in ConversorApp.java:34-36

RegistroConversion Record Structure

History entries are stored using the RegistroConversion record class, which is a Java record type providing immutable data storage.

Record Fields

record RegistroConversion(
    String monedaBase,      // Base currency code (e.g., "USD")
    String monedaObjetivo,  // Target currency code (e.g., "ARS")
    double cantidad,        // Amount converted
    double resultado,       // Conversion result
    LocalDateTime fechaHora // Timestamp of conversion
)
The RegistroConversion record is defined in /workspace/source/src/lad/com/alura/conversormoneda/modelos/RegistroConversion.java:6

Custom toString() Method

The record overrides the toString() method to provide formatted output:
@Override
public String toString() {
    DateTimeFormatter formato = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
    return "[" + fechaHora.format(formato) + "] " + cantidad + " " + 
           monedaBase + " =>> " + resultado + " " + monedaObjetivo;
}
This custom formatting ensures consistent, readable history output.
Custom toString() implementation is in RegistroConversion.java:9-13

How History is Created

After each successful conversion:
  1. A new RegistroConversion object is created with:
    • Base currency code
    • Target currency code
    • Original amount
    • Conversion result
    • Current timestamp (LocalDateTime.now())
  2. The record is added to the historial ArrayList
  3. The list persists for the entire session
RegistroConversion registro = new RegistroConversion(
    base, objetivo, cantidad, resultado, LocalDateTime.now()
);
historial.add(registro);
History creation happens in ConversorApp.java:83-84 after each conversion

History Persistence

The history is stored in memory using an ArrayList<RegistroConversion> and persists only during the current application session. When you exit the application (option 8), the history is cleared.
The history list is initialized at application startup:
List<RegistroConversion> historial = new ArrayList<>();
History list initialization is in ConversorApp.java:18

Using Lambda Expressions

The history display uses Java’s functional programming features:
historial.forEach(System.out::println);
This lambda expression iterates through all records and prints each one using the custom toString() method, providing clean and efficient code.
Lambda-based display is implemented in ConversorApp.java:37

Build docs developers (and LLMs) love