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 * the angle from the original heading to the new heading be a. 065 * The turn should be annotated as:<p> 066 * 067 * <pre> 068 * Continue if a < 10 069 * Turn slight right if 10 <= a < 60 070 * Turn right if 60 <= a < 120 071 * Turn sharp right if 120 <= a < 179 072 * U-turn if 179 <= a 073 * </pre> 074 * 075 * and likewise for left turns. 076 * 077 * @requires 0 <= oldHeading < 360 078 * @requires 0 <= newHeading < 360 079 * @param origHeading the start heading 080 * @param newHeading the desired new heading 081 * @return English directions to go from the old heading to the 082 * new one. 083 */ 084 protected String getTurnString(double origHeading, double newHeading) { 085 throw new RuntimeException("Not yet implemented"); 086 } 087 }