matthewalangreen
4/11/2017 - 5:39 PM

RoadTrip.java

import java.util.*;
public class RoadTrip
{
    private ArrayList<GeoLocation> locations;
    
    public RoadTrip()
    {
        locations = new ArrayList<GeoLocation>();
    }
    
    public void addStop(String name, double latitude, double longitude)
    {
        locations.add(new GeoLocation(name,latitude,longitude));
    }
    
    public double getTripLength()
    {
        GeoLocation curr = locations.get(0);
        double distance = 0;
        for(int i = 1; i<locations.size(); i++)
        {
            distance += locations.get(i).distanceFrom(curr);
            curr = locations.get(i);
        }
        return distance;
    }
    
    public int getNumberOfStops()
    {
        return locations.size();
    }
    
    public String toString()
    {
        String message = "";
        for(int i = 0; i<locations.size(); i++)
        {
            int item = i+1;
            message += Integer.toString(item)+". "+locations.get(i).toString()+"\n";
        }
        return message;
        
    }
    
    
    
    
}