#469 Finding the Active Quote by Currency and Date
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
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor