001 /**
002 *
003 * <h2>NWSFB06</h2>
004 *
005 *
006 * @author Matthew Hough
007 * @version .01, 6/2/07
008 * @assignment.number A19015
009 * @prg.usage NWSFB06 fb = new NWSFB06(strStaWea)
010 * This class has one public method that accepts a two-digit altitude string and
011 * outputs the associated weather for that altitude.
012 */
013 public class NWSFB06 implements NWS {
014
015 /* ********************************************************************** */
016 /* ************************** Setup Variables *************************** */
017 /* ********************************************************************** */
018 private String strStaWea, strStaID, strWinDir, strWinTemp, strWinSpeed;
019
020 /* ********************************************************************** */
021 /* **************************** Functions ******************************* */
022 /* ********************************************************************** */
023
024 /**
025 * Returns a formatted string that shows the returns the seven character
026 * altitude weather, the Wind Direction, Wind Speed and Wind Temperature in
027 * a specific format.
028 *
029 * <pre>
030 *
031 * The Weather for SEA at 24000 feet is 2917-26
032 * which translates into:
033 * Wind Direction of 290 degrees
034 * Wind Speed of 17 knots
035 * Wind Temperature of -26 degrees Celsius
036 * ...etc...
037 * </pre>
038 *
039 * @param strVar
040 * Any string
041 * @return
042 */
043 public String getWeather(String strAlt) {
044 String strAltitude = strAlt + "000";
045 String strStaID = getStationID();
046 String strAltWea = getAltWea(strAlt);
047 getWindDir(strAlt);
048 getWindSpeed(strAlt);
049 getWindTemp(strAlt);
050 String strOutput = "The weather for " + strStaID + " at " + strAltitude
051 + " is " + strAltWea + "\r\n" + "which translates into:\r\n"
052 + strWinDir + strWinSpeed + strWinTemp;
053 return strOutput;
054 }
055
056 public void status(String strVar) {
057
058 }
059
060 /**
061 * At a given altitude, returns the Wind Direction as a three digit string.
062 *
063 * @param strAlt
064 * A two character string representing the altitude in thousands.
065 * @return A three digit string representing the wind direction.
066 */
067 public String getWindDir(String strAlt) {
068 String strAltWea = getAltWea(strAlt);
069 if (strAltWea.startsWith(" ")) {
070 strWinDir = "n/a";
071 } else if (strAltWea.startsWith("9900")) {
072 strWinDir = "Calm";
073 } else {
074 strWinDir = strAltWea.substring(0, 2) + "0 degrees";
075 }
076 return strWinDir;
077 }
078
079 /**
080 * At a given altitude, returns the Wind Speed, in knots, as a two or three
081 * digit string.
082 *
083 * @param strAlt
084 * A two character string representing the altitude in thousands.
085 * @return strWinSpeed A 2 character string indicating the Wind Speed in
086 * knots.
087 */
088 public String getWindSpeed(String strAlt) {
089 String strAltWea = getAltWea(strAlt);
090 if (strAltWea.startsWith(" ")) {
091 strWinSpeed = "n/a";
092 } else if (strAltWea.startsWith("9900")) {
093 strWinSpeed = "";
094 } else {
095 strWinSpeed = strAltWea.substring(2, 4) + " knots";
096 }
097 return strWinSpeed;
098 }
099
100 /**
101 * Returns a formatted string that shows the returns the seven character
102 * altitude weather, the Wind Direction, Wind Speed and Wind Temperature in
103 * a specific format.
104 *
105 * @return The formatted string (the seven character altitude weather, the
106 * Wind Direction, Wind Speed and Wind Temperature).
107 */
108 public String getWindTemp(String strAlt) {
109 String strAltWea = getAltWea(strAlt);
110 if (strAltWea.startsWith("9900")) {
111 strWinTemp = "";
112 return strWinTemp;
113 }
114 strAltWea = getAltWea(strAlt).trim();
115 if (strAltWea.length() == 7) {
116 strWinTemp = strAltWea.substring(4, 7)
117 + " degrees";
118 } else if (strAltWea.length() == 6) {
119 strWinTemp = "-" + strAltWea.substring(4, 6)
120 + " degrees";
121 } else if (strAltWea.length() == 4) {
122 strWinTemp = "n/a";
123 } else {
124 strWinTemp = "n/a";
125 }
126 return strWinTemp;
127 }
128
129 /**
130 * Main Constructor. Accepts a string of about 70 characters representing
131 * the Station Weather and returns formatted lines. Saves the input string
132 * to the strStaWea variable.
133 *
134 * @param strStationWeather
135 * A string of about 70 characters representing the Station
136 * Weather.</em>
137 */
138 public NWSFB06(String strStationWeather) {
139 strStaWea = new String(strStationWeather + " ");
140 }
141
142 /**
143 * Extracts the Station ID from the first three characters of the Station
144 * Weather.
145 *
146 * @return strStaID The first three characters of the station ID as a
147 * string.
148 */
149 public String getStationID() {
150 strStaID = new String(strStaWea.substring(0, 3));
151 return strStaID;
152 }
153
154 /**
155 * @param strAlt
156 * A two character string representing the altitude.
157 * @return strOutput The formatted lines.
158 */
159 public String getPrintLine(String strAlt)
160 /*
161 * Returns the formatted lines. Accepts a two character string representing
162 * the altitude.
163 */
164 {
165 String strAltitude = strAlt + "000";
166 String strStationID = getStationID();
167 String strAltWea = getAltWea(strAlt);
168 String strOutput = new String("\tThe weather for " + strStationID
169 + " at " + strAltitude + " feet is " + strAltWea);
170 return strOutput;
171 }
172
173 /**
174 * Extracts the 7 character weather string from a specific altitude.
175 *
176 * @param strAlt
177 * A two character string representing the altitude.
178 * @return strAltWea The complete altitude weather (4-7 characters) as a
179 * string.
180 */
181 public String getAltWea(String strAlt) {
182 int intAlt1 = getPos(strAlt);
183 int intAlt2;
184 if (intAlt1 == 4) {
185 intAlt2 = intAlt1 + 4;
186 } else {
187 intAlt2 = intAlt1 + 7;
188 }
189 String strAltWea = strStaWea.substring(intAlt1, intAlt2);
190 return strAltWea;
191 }
192
193 /**
194 * Determines the starting position of the Altitude Weather based on the
195 * Altitude.
196 *
197 * @param strAlt
198 * A two character string representing the altitude.
199 * @return intAlt An integer representing the starting position of the
200 * altitude weather for the altitude in question.
201 */
202 public int getPos(String strAlt) {
203 int intAlt = Integer.parseInt(strAlt);
204 switch (intAlt) {
205 case 03:
206 intAlt = 4;
207 break;
208 case 06:
209 intAlt = 9;
210 break;
211 case 9:
212 intAlt = 17;
213 break;
214 case 12:
215 intAlt = 25;
216 break;
217 case 18:
218 intAlt = 33;
219 break;
220 case 24:
221 intAlt = 41;
222 break;
223 case 30:
224 intAlt = 49;
225 break;
226 case 34:
227 intAlt = 56;
228 break;
229 case 39:
230 intAlt = 63;
231 break;
232 }
233 return intAlt;
234 }
235
236 }