Gives advice to the user on which trains to take to reach a destination
public class TripAdvisor {
private Station source;
private Station destination;
private double cost;
/**
*
* @param path the shortest path returned by the shortestPath method implementation
*/
TripAdvisor(ArrayList<Station> path)
{
Lane color=null;
ArrayList<Station> changeStation =new ArrayList<Station>();//used to identify when the user needs to change lines
ArrayList<Object> trains=new ArrayList<>();//list of trains the user need to take to reach a station
for(int i=0;i<(path.size()-1);i++)
{
Station current=path.get(i);
Station next=path.get(i+1);
for (Connection e : current.adjacencies)
{
if(e.getTarget().equals(next))
{
Lane train=e.getLaneColor();
trains.add(train);
if(!e.getLaneColor().equals(color)&&(color!=null))
{
changeStation.add(current);
}
}
color=e.getLaneColor();
}
}
System.out.println("trains"+ "$" +trains);
if(trains.size()==1)
{
int q;
System.out.println("Take a "+ trains.get(0) +"liner from" + path.get(0) +"to reach" + path.get( q=path.size()));
}
else
{
System.out.println("Take a "+ trains.get(0) +"liner from" + path.get(0)+ "Get down at" + changeStation.get(0));
}
}
}
/**
*
* @author PrasannaAarthiB
* This has all the lines in the metro.They are represented by different colors
*/
public enum Lane{
RED,BLUE,GREEN,YELLOW,BLACK
}