001 package ps2;
002
003 import java.util.Iterator;
004 import java.text.*;
005
006
007 /**
008 * <p>
009 * A RouteFormatter class knows how to create a textual description of
010 * directions from one location to another. The class is abstract to
011 * support different textual descriptions.
012 * </p>
013 *
014 * <p>
015
016 * These classes may be thought of as <i>views</i> on the Route model.
017 * (see <a
018 * href="http://java.sun.com/blueprints/patterns/MVC-detailed.html">Sun's
019 * buzzword-filled explanation</a> of this design pattern)
020 * </p>
021 **/
022 public abstract class RouteFormatter {
023
024 /**
025 * <p>
026 * Give directions for following this Route, starting at its
027 * start point and facing in the specified heading.
028 * </p>
029 *
030 * <p>
031 * This method should call <tt>computeLine</tt> for each
032 * geographical feature in this route and concatenate the results
033 * into a single String.
034 * </p>
035 *
036 * @requires 0 ≤ heading < 360 && route != null
037 * @param route The route for which to print directions.
038 * @param heading The initial heading.
039 * @return A newline-terminated directions <tt>String</tt> giving
040 * human-readable directions from start to end along this route.
041 **/
042 public String computeDirections(Route route, double heading) {
043 throw new RuntimeException("Not yet implemented");
044 }
045
046
047 /**
048 * Computes a single line of a multi-line directions String that
049 * represents the intructions for traversing a single geograhpical
050 * feature.
051 *
052 * @requires geoFeature != null
053 * @param geoFeature The geographical feature to traverse.
054 * @param origHeading The initial heading
055 * @return A newline-terminated <tt>String</tt> that gives
056 * directions on how to traverse this geographical feature.
057 **/
058 public abstract String computeLine(GeoFeature geoFeature,
059 double origHeading);
060
061
062 /**
063 * Computes directions to turn based on the heading change. Let
064 * a be the angle from the original heading to the new heading (that
065 * is, a is the difference between the two headings).
066 * The turn should be annotated as:<p>
067 *
068 * <pre>
069 * Continue if a < 10
070 * Turn slight right if 10 ≤ a < 60
071 * Turn right if 60 ≤ a < 120
072 * Turn sharp right if 120 ≤ a < 179
073 * U-turn if 179 ≤ a
074 * </pre>
075 *
076 * and likewise for left turns.
077 *
078 * @requires 0 ≤ origHeading < 360
079 * @requires 0 ≤ newHeading < 360
080 * @param origHeading the start heading
081 * @param newHeading the desired new heading
082 * @return English directions to go from the old heading to the
083 * new one.
084 */
085 protected String getTurnString(double origHeading, double newHeading) {
086 throw new RuntimeException("Not yet implemented");
087 }
088 }