import java.util.*;
import java.time.*;
public class Solution {
public static class MarketingEngine {
List<Event> list;
public MarketingEngine(List<Event> events) {
this.list = events;
}
public void sendCustomerNotifications(Customer customer) {
List<Event> result = new ArrayList<>();
String customerCity = customer.getCity();
for (Event event : list) {
if (customerCity.equals(event.getCity())) {
result.add(event);
}
}
for(Event eve : result) {
System.out.println(eve.getCity() + eve.getName() + eve.getEventDate());
}
}
public void sendCustomerNotificationsbByClosestBirthdayEvent(Customer customer) {
LocalDate temp = LocalDate.of(2100, 1, 1);
LocalDate customerBirthDay = customer.getBirthdate();
LocalDate currentDate = LocalDate.of(2023, 4, 14);
Event tempEvent = null;
for(Event event : list) {
if(customerBirthDay.isBefore(event.getEventDate()) && temp.compareTo(event.getEventDate()) > 0 && currentDate.isBefore(event.getEventDate()) ) {
temp = event.getEventDate();
tempEvent = event;
}
}
if (tempEvent != null) {
System.out.println(tempEvent.getEventDate() + tempEvent.getName() + tempEvent.getCity());
}
}
public void sendCustomerNotificationsbByClosestLocationEvent(Customer customer) {
String cusCity = customer.getCity();
City customerCity = City.AllCities.get(cusCity);
PriorityQueue<Event> clostLocation = new PriorityQueue<>((a, b) -> ((int)(Math.sqrt(City.AllCities.get(b.getCity()).X - customerCity.X * (City.AllCities.get(b.getCity()go", LocalDate.of(2023, 7, 4)),
new Event(8, "LadyGaGa", "San Francisco", LocalDate.of(2023, 7, 7)),
new Event(9, "LadyGaGa", "Washington", LocalDate.of(2023, 5, 22)),
new Event(10, "Metallica", "Chicago", LocalDate.of(2023, 1, 1)),
new Event(11, "Phantom of the Opera", "San Francisco", LocalDate.of(2023, 5, 9)),
new Event(12, "Phantom of the Opera", "Chicago", LocalDate.of(2024, 5, 15)));
var customer = new Customer(1, "John", "New York", LocalDate.of(1995, 05, 10));
MarketingEngine engine = new MarketingEngine(events);
//engine.sendCustomerNotifications(customer);
//engine.sendCustomerNotificationsbByClosestBirthdayEvent(customer);
engine.sendCustomerNotificationsbByClosestLocationEvent(customer);
}
} |