As a member of the cab finder | CareerCup
As a member of the cab finder app team, you are tasked with implementing a CabFinder class that has the following minimal public interface:class CabFinder implements CabStatusListener {
/**
* Initiates CabFinder. Called only once per app startup.
* @app An application object providing services implemented by
* the rest of the application.
* @maxCabs Nearest number of cabs that can be returned to the user
*/
public void initialize(CabApp app, int maxCabs) {
//Insert code here...
}
/**
* Gets nearest cabs within 1km of the current user's location.
* These must be the *nearest possible* @maxCabs in the 1km area.
* @return An unordered list of the nearest cabs.
*/
public Cab[] getNearestCabs() {
//Insert code here...
}
/**
* Asynchronous Callback per CabStatusListener (see below). Called when the position of a cab has changed.
*/
void onCabPositionChanged(Cab cab) {
//Insert code here…
}
/**
* Asynchronous Callback per CabStatusListener (see below). Called when a cab's availability changes.
* @cab The cab whose availability has changed
* @isAvailable true if the cab is now available, false otherwise
*/
void onCabAvailabilityChanged (Cab cab, boolean isAvailable) {
//Insert code here…
}
}
Supporting Classes:
Here are the classes and utilities that are available for your use (you are not required to write any implementation for these classes)
/**
* Coordinates on a 2D map with a one meter granularity.
*/
class Position {
public int x;
public int y;
}
interface Cab {
/**
* Unique identifier of a cab.
*/
int getID();
/**
* Gets the current position of the cab
*/
Position getCabPosition();
/**
* Returns whether or not the cab is available
*/
boolean isAvailable();
}
/**
* Provides services implemented by the rest of the Cab Application.
*/
interface CabApp {
/**
* Gets the current location of the user
*/
Position getUserPosition();
/**
* Returns an iterator that gives access to the list of all cabs in the city
*/
Iterator<Cab> getCabs();
/**
* Registers a CabStatusListener object for change notifications of cab object data.
*/
void register(CabStatusListener listener);
}
/**
* The CabStatusListener interface
*/
interface CabStatusListener {
/**
* Called when the position of a cab has changed.
* @cab The cab object
*/
void onCabPositionChanged(Cab cab);
/**
* Called when a cab's availability changes.
* @cab The cab object
* @isAvailable true if the cab is available, false otherwise
*
*/
void onCabAvailabilityChanged (Cab cab, boolean isAvailable);
}
Read full article from As a member of the cab finder | CareerCup
No comments:
Post a Comment