//Position Implementation for Flight Planner Program
//by www.neiljohan.com

import java.util.*;

public class PositionImpl implements Position
{
    private String tLong, tLongMinutes, tLongSeconds, tLat, tLatMinutes, tLatSeconds;
    private char tLongDirection, tLatDirection;
    private String tempLong, tempLat;
    
    public PositionImpl (final String tInput)
        {
            StringTokenizer tTokensOnLine = new StringTokenizer(tInput, ":");
            tempLong = tTokensOnLine.nextToken();
            tempLat = tTokensOnLine.nextToken();

                //Get Longitude Values
            tTokensOnLine = new StringTokenizer(tempLong, "-");
            tLong = tTokensOnLine.nextToken();
            tLongMinutes = tTokensOnLine.nextToken();
            tLongSeconds = tTokensOnLine.nextToken();

            String tThisToken = tTokensOnLine.nextToken();
            tLongDirection = tThisToken.charAt(0);

                //Get Latitude Values
            tTokensOnLine = new StringTokenizer(tempLat, "-");
            tLat = tTokensOnLine.nextToken();
            tLatMinutes = tTokensOnLine.nextToken();
            tLatSeconds = tTokensOnLine.nextToken();

            tThisToken = tTokensOnLine.nextToken();
            tLatDirection = tThisToken.charAt(0);
        }

    public double getLongitude()
        {
            double iLong = new Double(tLong).doubleValue();
            return iLong;
        }

    public double getLongMinutes()
        {
            double iLongMinutes = new Double(tLongMinutes).doubleValue();
            return iLongMinutes;
        }

    public double getLongSeconds()
        {
            double iLongSeconds = new Double(tLongSeconds).doubleValue();
            return iLongSeconds;
        }

    public char getLongDirection()
        {
            return tLongDirection;
        }

    public double getLatitude()
        {
            double iLat = new Double(tLat).doubleValue();
            return iLat;
        }

    public double getLatMinutes()
        {
            double iLatMinutes = new Double(tLatMinutes).doubleValue();   
            return iLatMinutes;
        }

    public double getLatSeconds()
        {
            double iLatSeconds = new Double(tLatSeconds).doubleValue();
            return iLatSeconds;
        }

    public char getLatDirection()
        {
            return tLatDirection;
        }

    public void setLongitude(final double newLat)
        {
            tLong = "" + newLat;
        }

    public void setLatitude(final double newLong)
        {
            tLat = "" + newLong;
        }

    public String toString()
        {
            return "" + tLong + "-" + tLongMinutes + "-" + tLongSeconds + "-" + tLongDirection + ":" + tLat + "-" + tLatMinutes + "-" + tLatSeconds + "-" + tLatDirection;
        }

    public int hashCode()
        {
            String West = tLong;
            String East = tLat;
            int iWest = new Integer(West).intValue();
            int iEast = new Integer(West).intValue();
            return iWest*360 + iWest*60;
        }

    public boolean equals(final Object pObject)
        {
            if (! (pObject instanceof PositionImpl)){
                return false;
            }
            {
                return tLong==((PositionImpl)pObject).tLong && tLat==((PositionImpl)pObject).tLat;
            }
        }
}



