#469 Finding the Active Quote by Currency and Date

Companies:
Alfa-Bank
Themes:
JavaCollections & GenericsCode Review

Which collection type is best for Quoter?

public interface Quoter {

    void put(Quote q);

    Quote get(String currency, Date anyDate);

    /*
    Example:
    quoterImpl.put(new Quote("USD", 1, "JANUARY FIRST"));
    quoterImpl.put(new Quote("EUR", 3, "JANUARY FIRST"));
    quoterImpl.put(new Quote("USD", 2, "JANUARY THIRD"));

    quoterImpl.get("USD", "JANUARY FIRST")
        -> Quote("USD", 1, "JANUARY FIRST")

    quoterImpl.get("EUR", "JANUARY FIRST")
        -> Quote("EUR", 3, "JANUARY FIRST")

    quoterImpl.get("USD", "JANUARY SECOND")
        -> Quote("USD", 1, "JANUARY FIRST")

    -----------------------------------------

    ! No two quotes for the same currency
    may be received for the same date !
    */
}

public class Quote {
    // currency code
    String currency;

    // quote price in arbitrary units
    double price;

    // date from which the quote is active
    Date activeFrom;

    // getters, setters, constructors
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in