<pre>public Assistant findNearestAvailable(int location) { Iterator<Assistant> it = assistants.iterator(); Assistant nearestAssistant = null; int nearestDistance = Integer.MAX_VALUE; int nearestID = Integer.MAX_VALUE; while(it.hasNext()) { Assistant assistant = it.next(); if(assistant.isAvailable()) { int distance = location - assistant.getLocation(); if(distance < nearestDistance){ nearestDistance = distance; nearestAssistant = assistant; } else if(){ } else if(distance == nearestDistance){ if(identity < nearestID){ nearestID = identity; nearestAssistant = assistant; } } } } return nearestAssistant; }
import java.lang.Math
Quote:int distance = location - assistant.getLocation();
int distance = Math.abs(location - assistant.getLocation());
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)