001 package ps2; 002 003 /** 004 * <p> 005 * A GeoSegment models a straight line segment on the earth. 006 * GeoSegments are immutable. 007 * </p> 008 * 009 * <p> 010 * A compass heading is a nonnegative real number less than 360. In 011 * compass headings, north = 0, east = 90, south = 180, and west = 012 * 270. 013 * </p> 014 * 015 * <p> 016 * When used in a map, a GeoSegment might represent part of a street, 017 * boundary, or other feature. 018 * As an example usage, this map 019 * <pre> 020 * Penny Lane a 021 * | 022 * i--j--k Abbey Road 023 * | 024 * z 025 * </pre> 026 * could be represented by the following GeoSegments: 027 * ("Penny Lane", a, i), ("Penny Lane", z, i), 028 * ("Abbey Road", i, j), and ("Abbey Road", j, k). 029 * </p> 030 * 031 * <p> 032 * A name is given to all GeoSegment objects so that it is possible to 033 * differentiate between two GeoSegment objects with identical 034 * GeoPoint endpoints. Equality between GeoSegment objects requires 035 * that the names be equal String objects and the end points be equal 036 * GeoPoint objects. 037 * </p> 038 * 039 * @specfield name : String // name of the geographic feature identified 040 * @specfield p1 : GeoPoint // first endpoint of the segment 041 * @specfield p2 : GeoPoint // second endpoint of the segment 042 * @derivedfield length : real // straight-line distance between p1 and p2, in miles 043 * @derivedfield heading : angle // compass heading from p1 to p2, in degrees 044 **/ 045 public class GeoSegment { 046 047 // FIELDS 048 049 // Constructors 050 051 /** 052 * @requires name != null && p1 != null && p2 != null 053 * @effects constructs a new GeoSegment with the specified 054 * name and endpoints 055 **/ 056 public GeoSegment(String name, GeoPoint p1, GeoPoint p2) { 057 throw new RuntimeException("Not yet implemented"); 058 } 059 060 061 /** 062 * Checks that the representation invariant holds (if any). 063 **/ 064 // Throws a RuntimeException if the rep invariant is violated. 065 private void checkRep() throws RuntimeException { 066 throw new RuntimeException("Not yet implemented"); 067 } 068 069 070 // Producers 071 072 /** 073 * Returns a new GeoSegment like this one, but with its endpoints 074 * reversed. 075 * @return a new GeoSegment gs such that 076 * gs.name = this.name 077 * && gs.p1 = this.p2 078 * && gs.p2 = this.p1 079 **/ 080 public GeoSegment reverse() { 081 throw new RuntimeException("Not yet implemented"); 082 } 083 084 085 // Observers 086 087 /** 088 * @return the name of this GeoSegment. 089 **/ 090 public String getName() { 091 throw new RuntimeException("Not yet implemented"); 092 } 093 094 095 /** 096 * @return first endpoint of the segment. 097 **/ 098 public GeoPoint getP1() { 099 throw new RuntimeException("Not yet implemented"); 100 } 101 102 103 /** 104 * @return second endpoint of the segment. 105 **/ 106 public GeoPoint getP2() { 107 throw new RuntimeException("Not yet implemented"); 108 } 109 110 111 /** 112 * @return the length of the segment, using the flat-surface, 113 * near-Seattle approximation. 114 **/ 115 public double getLength() { 116 throw new RuntimeException("Not yet implemented"); 117 } 118 119 120 /** 121 * @requires this.length != 0 122 * @return the compass heading from p1 to p2, in degrees, using 123 * the flat-surface, near-Seattle approximation. 124 **/ 125 public double getHeading() { 126 throw new RuntimeException("Not yet implemented"); 127 } 128 129 130 /** 131 * Compares the specified Object with with this GeoSegment for 132 * equality. 133 * @return gs != null && (gs instanceof GeoSegment) 134 * && gs.name = this.name && gs.p1 = this.p1 && gs.p2 = this.p2 135 **/ 136 public boolean equals(Object gs) { 137 throw new RuntimeException("Not yet implemented"); 138 } 139 140 141 /** 142 * @return a valid hashcode for this. 143 **/ 144 public int hashCode() { 145 // This implementation will work, but you may want to modify 146 // it later for improved performance. If you do change the 147 // implementation, make sure it satisfies the hashCode 148 // invariant. That is, if equals returns true for two 149 // objects, then they must have the same hashCode. 150 return (1); 151 } 152 153 154 /** 155 * @return a string representation of this. 156 **/ 157 public String toString() { 158 throw new RuntimeException("Not yet implemented"); 159 } 160 161 } // GeoSegment