#313 Finding the First Order and Sorting Deliveries
Implement the methods:
-
The
findFirstOrdermethod accepts a list of orders and must return the first / earliest order in the list according to theDeliveryDatefield. If the list is empty, the method must return an order created by its default constructor (“empty order”). - The method for printing delivery addresses also uses a list of orders and must print addresses sorted by delivery date from earliest to latest, without duplicates. Each address must be printed on a new line. If the list contains duplicates, only the first order should be printed to avoid visiting the same address repeatedly. Return the sorted collection.
public class DeliveryOrderStream {
public static DeliveryOrder findFirstOrder(List<DeliveryOrder> orders) {
return null;
}
public static Collection<DeliveryOrder> printAddressesToDeliver(Collection<DeliveryOrder> orders) {
return null;
}
public static void main(String[] args) {
List<DeliveryOrder> orders = List.of(
new DeliveryOrder(1L, "112 Mammoth Street, Colorado Springs, CO 80911", LocalDate.of(2021, 9, 3)),
new DeliveryOrder(2L, "369 Woodside Court, Troy, NY 12180", LocalDate.of(2021, 9, 5)),
new DeliveryOrder(3L, "837 Bowman Street, Helena, MT 59601", LocalDate.of(2021, 9, 2)),
new DeliveryOrder(4L, "112 Mammoth Street, Colorado Springs, CO 80911", LocalDate.of(2021, 9, 3)),
new DeliveryOrder(5L, "112 Mammoth Street, Colorado Springs, CO 80911", LocalDate.of(2021, 10, 3)),
new DeliveryOrder(6L, "112 Mammoth Street, Colorado Springs, CO 80911", LocalDate.of(2021, 8, 3))
);
System.out.println(findFirstOrder(orders));
printAddressesToDeliver(orders).forEach(System.out::println);
}
}
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