001 package ps2; 002 003 import java.text.DecimalFormat; 004 005 006 /** 007 * <p> 008 * The DrivingRouteFormatter class creates a textual description of 009 * directions for traversing a route that are suitable for a driver of 010 * a vehicle. 011 * </p> 012 * 013 * <p> 014 * Calling <tt>computeDirections</tt> should produce directions in the 015 * following form: 016 * </p> 017 * 018 * <p> 019 * <tt> 020 * Turn right onto Baker Street and go 1.2 miles.<br /> 021 * Turn slight left onto MacGregor Street and go 0.8 miles.<br /> 022 * Turn sharp right onto Burton street and go 2.3 miles.<br /> 023 * Continue onto Connor Street and go 1.1 miles.<br /> 024 * </tt> 025 * </p> 026 * 027 * <p> 028 * Each line should correspond to a single geographic feature of the 029 * route. In the first line, "Baker Street" is the name of the first 030 * geographical feature of the route, and "1.2 miles" is the length of 031 * the geographic feature. The length should be reported to 032 * tenth-of-a-mile precision. Each line should be terminated by a 033 * newline and should include no extra spaces other than those shown 034 * above. 035 * </p> 036 **/ 037 public class DrivingRouteFormatter extends RouteFormatter { 038 039 // You may use this object to round floating point values to one 040 // decimal place. Alternately, you may do so with String.format 041 // and the format specifier "%.1f". 042 private static final DecimalFormat formatter = new DecimalFormat("0.0"); 043 044 045 /** 046 * <p> 047 * Computes a single line of a multi-line directions String that 048 * represents the instructions for traversing a single 049 * geographical feature. 050 * </p> 051 * 052 * <p> 053 * Calling <tt>computeLine</tt> with a GeoFeature instance and an 054 * initial heading should produce a newline-terminated String in 055 * the following form: 056 * </p> 057 * 058 * <p> 059 * <tt> 060 * Turn sharp left onto MacGregor Street and go 0.8 miles.<br /> 061 * </tt> 062 * </p> 063 * 064 * <p> 065 * In the output above, "MacGregor Street" represents the name of 066 * the geographical feature, and "0.8 miles" is the length of the 067 * geographical feature. The length should be reported to 068 * tenth-of-a-mile precision. The String should be terminated by 069 * a newline and should include no extra spaces other than those 070 * shown above. 071 * </p> 072 * 073 * @requires 0 ≤ origHeading < 360 074 * @param geoFeature The geographical feature to traverse. 075 * @param origHeading The initial heading 076 * @return A newline-terminated <tt>String</tt> that gives 077 * directions on how to traverse this geographical feature. 078 **/ 079 public String computeLine(GeoFeature geoFeature, double origHeading) { 080 throw new RuntimeException("Not yet implemented"); 081 } 082 }