Problem Statement: Air Traffic Monitoring System
Airtraffice in modern airlines is monitored using advanced tracking systems. Each aircraft is
equipped with a tracking device that sends information about its altitude and distance traveled at
specific intervals. A warning is issued if the average altitude during this interval exceeds a certain
value, H meters.
Complete a class AirTrafficMonitoringService which implements an
interface IAirTrafficMonitoringService:
void registerAircraft(int aircraftId): Create an object of class Aircraft using aircraftId. The
definition of the Aircraft class is given in the code stub. This class stores the
values aircraftId, lastPolledInfo, and numberOfWarningsIssued.
Aircraft getAircraftInfo(int aircraftId): Returns the object that represents the aircraft with
the aircraftId.
boolean polledAircraftInfo(int aircraftId, long distanceTraveledInMeters, long
altitudeInMeters, long epochTime): Calculate and check if the average altitude is greater
than H units. If it is, return true; otherwise, return false.
Average altitude = altitudeInMeters / (epochTime - lastPolledEpochTime)
List<Long> warningHistory(int aircraftId, int K): Returns a list of the last K timestamps when
a warning was issued for this aircraft. The list should be in descending order.
import [Link];
import [Link];
public class Aircraft {
private int aircraftId;
private long lastPolledInfo; // Last time this aircraft was polled
private int numberOfWarningsIssued;
private List<Long> warningTimestamps; // Store timestamps of warnings
public Aircraft(int aircraftId) {
[Link] = aircraftId;
[Link] = 0; // Initialize as needed
[Link] = 0;
[Link] = new ArrayList<>(); // Initialize the list for warning timestamps
}
public long getLastPolledInfo() {
return lastPolledInfo;
public void updateLastPolledInfo(long altitude, long time) {
[Link] = time; // Update with the current time
// Store altitude if needed
public void incrementWarningCount(long timestamp) {
[Link]++;
[Link](timestamp); // Store the timestamp of the warning
public List<Long> getWarningTimestamps() {
return warningTimestamps;
public interface IAirTrafficMonitoringService {
void registerAircraft(int aircraftId);
Aircraft getAircraftInfo(int aircraftId);
boolean polledAircraftInfo(int aircraftId, long distanceTraveledInMeters, long altitudeInMeters,
long epochTime);
List<Long> warningHistory(int aircraftId, int K);
}
import [Link];
import [Link];
import [Link];
import [Link];
public class AirTrafficMonitoringService implements IAirTrafficMonitoringService {
private Map<Integer, Aircraft> aircrafts = new HashMap<>();
private static final long H = 10000; // Set the altitude limit (H) in meters
@Override
public void registerAircraft(int aircraftId) {
// Empty method
@Override
public Aircraft getAircraftInfo(int aircraftId) {
// Empty method
return null;
@Override
public boolean polledAircraftInfo(int aircraftId, long distanceTraveledInMeters, long
altitudeInMeters, long epochTime) {
// Empty method
return false;
@Override
public List<Long> warningHistory(int aircraftId, int K) {
// Empty method
return null;
import [Link];
public class Main {
public static void main(String[] args) {
// Create an instance of the AirTrafficMonitoringService
AirTrafficMonitoringService service = new AirTrafficMonitoringService();
// Register some aircraft
[Link](1);
[Link](2);
[Link](3);
// Simulate polling aircraft info
long currentTime = [Link]() / 1000; // Get current time in seconds
// First Polling: Aircraft 1
boolean warning1 = [Link](1, 10000, 12000, currentTime);
[Link]("Aircraft 1 Warning Issued: " + warning1); // Expect false
// Update last polled info for aircraft 1
[Link](1).updateLastPolledInfo(12000, currentTime);
// Second Polling: Aircraft 1 with higher altitude
currentTime += 3600; // Simulate 1 hour later
boolean warning2 = [Link](1, 10000, 15000, currentTime);
[Link]("Aircraft 1 Warning Issued: " + warning2); // Expect true
// Check warning history for aircraft 1
List<Long> warningHistory1 = [Link](1, 5);
[Link]("Aircraft 1 Warning History: " + warningHistory1);
// First Polling: Aircraft 2
boolean warning3 = [Link](2, 10000, 9000, currentTime);
[Link]("Aircraft 2 Warning Issued: " + warning3); // Expect false
// Update last polled info for aircraft 2
[Link](2).updateLastPolledInfo(9000, currentTime);
// Second Polling: Aircraft 2 with higher altitude
currentTime += 3600; // Simulate 1 hour later
boolean warning4 = [Link](2,