001 package ps2;
002
003
004 /**
005 * <p>
006 * A GeoPoint models a point on the earth. GeoPoints are immutable.
007 * </p>
008 *
009 * <p>
010 * North latitudes and east longitudes are represented by positive
011 * numbers. South latitudes and west longitudes are represented by
012 * negative numbers. In each case, the precision is to a millionth
013 * of a degree.
014 * </p>
015 *
016 * <p>
017 * The code may assume that the represented points are nearby Seattle.
018 * </p>
019 *
020 * <p>
021 * <b>Implementation hint</b>:<br /> Seattle is at approximately 47
022 * deg. 36 min. 35 sec. N latitude and 122 deg. 19 min. 59 sec. W
023 * longitude. There are 60 minutes per degree, and 60 seconds per
024 * minute. So, in decimal, these correspond to 47.609722 North
025 * latitude and -122.333056 East longitude. The constructor takes
026 * integers in millionths of degrees. To create a new GeoPoint
027 * located in Seattle, use: <tt>GeoPoint seattle = new
028 * GeoPoint(47609722, -122333056);</tt>
029 * </p>
030 *
031 * <p>
032 * Near Seattle, there are approximately 69.04 miles per degree of
033 * latitude and 47.574 miles per degree of longitude. An
034 * implementation should use these values when determining distances
035 * and headings.
036 * </p>
037 *
038 * @specfield latitude : real // measured in degrees latitude
039 * @specfield longitude : real // measured in degrees longitude
040 **/
041 public class GeoPoint {
042
043 /** Minimum value the latitude field can have in this class. **/
044 public static final int MIN_LATITUDE = -90 * 1000000;
045
046 /** Maximum value the latitude field can have in this class. **/
047 public static final int MAX_LATITUDE = 90 * 1000000;
048
049 /** Minimum value the longitude field can have in this class. **/
050 public static final int MIN_LONGITUDE = -180 * 1000000;
051
052 /** Maximum value the longitude field can have in this class. **/
053 public static final int MAX_LONGITUDE = 180 * 1000000;
054
055
056 /**
057 * Approximation used to determine distances and headings using a
058 * "flat earth" simplification.
059 **/
060 public static final double MILES_PER_DEGREE_LATITUDE = 69.04;
061
062 /**
063 * Approximation used to determine distances and headings using a
064 * "flat earth" simplification.
065 **/
066 public static final double MILES_PER_DEGREE_LONGITUDE = 46.574;
067
068
069 // FIELDS
070
071
072 // Constructors
073
074 /**
075 * @requires the (latitude, longitude) point expressed in
076 * millionths of a degree is valid, such that
077 * MIN_LATITUDE <= latitude <= MAX_LATITUDE and
078 * MIN_LONGITUDE <= longitude <= MAX_LONGITUDE
079 *
080 * @effects constructs a GeoPoint from a latitude and
081 * longitude given in millionths of degrees.
082 **/
083 public GeoPoint(int latitude, int longitude) {
084 throw new RuntimeException("Not yet implemented");
085 }
086
087
088 /**
089 * Checks that the representation invariant holds (if any).
090 * Throws an exception if the rep invariant is violated.
091 **/
092 private void checkRep() {
093 throw new RuntimeException("Not yet implemented");
094 }
095
096
097 // Observers
098
099 /**
100 * the latitude of the GeoPoint object, in millionths of degrees.
101 **/
102 public int getLatitude() {
103 throw new RuntimeException("Not yet implemented");
104 }
105
106
107 /**
108 * the longitude of the GeoPoint object, in millionths of degrees.
109 **/
110 public int getLongitude() {
111 throw new RuntimeException("Not yet implemented");
112 }
113
114
115 /**
116 * Computes the distance between GeoPoints.
117 * @requires gp != null
118 * @return The distance, in miles, from this to gp, using the
119 * flat-surface, near Seattle approximation.
120 **/
121 public double distanceTo(GeoPoint gp) {
122 throw new RuntimeException("Not yet implemented");
123 }
124
125
126 /**
127 * Computes the compass heading between GeoPoints.
128 * @requires gp != null && !this.equals(gp)
129 * @return The compass heading h from this to
130 * gp, in degrees, using the flat-surface, near Seattle
131 * approximation, such that 0 ≤ h < 360. In compass
132 * headings, north = 0, east = 90, south = 180, and west = 270.
133 **/
134 public double headingTo(GeoPoint gp) {
135 throw new RuntimeException("Not yet implemented");
136 }
137
138
139 /**
140 * Compares the specified Object with this GeoPoint for equality.
141 * @return gp != null && (gp instanceof GeoPoint)
142 * && gp.latitude = this.latitude && gp.longitude = this.longitude
143 **/
144 public boolean equals(Object gp) {
145 throw new RuntimeException("Not yet implemented");
146 }
147
148
149 /**
150 * @return a valid hashcode for this GeoPoint.
151 **/
152 public int hashCode() {
153 // This implementation will work, but you may want to modify
154 // it later for improved performance. If you do change the
155 // implementation, make sure it satisfies the hashCode
156 // invariant. That is, if equals returns true for two
157 // objects, then they must have the same hashCode.
158 return (1);
159 }
160
161
162 /**
163 * @return a string representation of this GeoPoint.
164 **/
165 public String toString() {
166 throw new RuntimeException("Not yet implemented");
167 }
168
169 } // GeoPoint