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