Question

In: Computer Science

METAR Abbreviations METAR (Meteorological Aviation Report) is a format for reporting weather information, either for pilots...

METAR Abbreviations

  • METAR (Meteorological Aviation Report) is a format for reporting weather information, either for pilots in pre-flight weather briefings or by meteorologists to aid them in weather forecasting.
  • Here is a sample METAR report:
    SPECI KPWK 042100Z 05010KT 10SM BKN030
    OVC036 M01/M08 A3049 RMK AO2 T10111078
    
    Translation:
    SPECI means that this is an unscheduled METAR report issued when certain criteria are met.
    KPWK is the airport identifier for Chicago Executive Airport 18 miles northwest of the city center.
    Z means Zulu time (Coordinated Universal Time): 4:21:00pm.
    KT means wind direction and speed: direction 50 degrees clockwise from North and speed 10 knots.
    SM means visibility: 10 miles.
    BKN means clouds with cloud bottoms at 3,000 ft. are broken (cover 5/8 to 7/8 of sky).
    OVC means that clouds with cloud bottoms at 3,600 ft. are overcast (cover all of the sky).
    M01/M08 means that the temperature is minus 1 Celsius and that the dew point is minus 8 Celsius.
    A indicates an altimeter pressure reading of 10.49 inches of mercury.
    RMK means that the Remarks Section follows.
    A02 indicates that the station is automated with a precipitation discriminator
    T10171017 is a breakdown of the temperature and dew point in eight digits separated into two groups of four.
  • For example, here is a METAR weather report for the Midway Station in Chicago, for midnight, January 7, 2014:
    METAR KMDW 070551Z 26013G17KT 10SM FEW020 
    M23/M27 A3024 RMK AO2 SLP276 4/010 
    T12331272 11228 21239 411831261 55003 $
    
  • Here is a METAR tutorial from Weather Underground to help you decode this METAR report. You can also consult Wikipedia for an overview of METAR.

Project 1 directions:

  1. Look up the English meanings of these METAR abbreviations online (Wikipedia is a good source):
    +  -  B  DZ  E  HZ  RA  SN
    
  2. Write a Java program that reads a METAR abbreviation, translates it to English if it is one of these eight abbreviations, then prints its English meaning. Use an if..else statement to do the translation.
  3. If the input does not match any of these eight abbreviations, print Unknown abbreviation.
  4. Name your Java project according to the standard naming convention: Proj1Smith, where you replace Smith by your last name. Also name your zip file Proj1Smith.zip
  5. Submit a zip file of your IntelliJ project folder.
  6. Note: don't use the == operator for String objects, use the String equals method instead as in the NumToWords Example in the num-to-words file.

Solutions

Expert Solution

import java.util.*;
import java.lang.*;
import java.io.*;

class Project
{
   public static void main (String[] args) throws java.lang.Exception
   {
       Scanner sc = new Scanner(System.in);
       String wReport = sc.nextLine(); //input should be given in a single line space seperated
       String[] codes = wReport.split(" "), preCodes = {"DZ", "HZ", "RA", "SN"};
       String[] preCodeMeanings = {"drizzle", "haze", "rain", "snow"}; //could have also used hashmap rather than array
       int l = codes.length, preCodesLength = preCodes.length;
      
       for(int i=0;i<l;i++){
           System.out.print(codes[i]+": ");
           String code = codes[i], subCode = code, ans = "";
           boolean flag = false;
           if(code.length() == 1){
               System.out.println("Unknown abbreviation");
               continue;
           }
           if(code.charAt(0) == '+' || code.charAt(0) == '-'){
               if(code.charAt(0) == '+')ans+="heavy";
               else ans+="light";
               subCode = code.substring(1);
           }
       int j = 0;
       for(j=0;j<preCodesLength;j++){
           String subSubCode = subCode.substring(0,2);
          if(subSubCode.equals(preCodes[j])){
             if(ans.length()>0)ans+=" "+preCodeMeanings[j];
             else ans+=preCodeMeanings[j];
             break;
          }
       }
       if(j < preCodesLength){
           flag = true;
       }
       if(subCode.length()>2){
           if(!(ans.equals("light") || ans.equals("heavy")) && flag == true){
               if(subCode.charAt(2) == 'B')ans+=" "+"began at time";
               else if(subCode.charAt(2) == 'E')ans+=" "+"ended at time";
              
               if(subCode.length() > 3){
                   String subSubCode = subCode.substring(3);
                   if(subSubCode.length()>0){
                       ans+=" "+subSubCode;
                       if(subCode.charAt(2) == 'B')ans+=" minutes after the top of the last hour";
                       else ans+=" minutes after the top of the last hour";
                       System.out.println(ans);
                       continue;
                   }
               }
           }
       }
       else if(flag == true){
           System.out.println(ans);
       }
       System.out.println("Unknown abbreviation");
       }
   }
}

Custom Input: KMSP 220853Z 36013KT 9SM -RAB5 FEW018 BKN030 OVC042 M03/M07 A3035 RMK AO2 SLP288

Output:

KMSP: Unknown abbreviation
220853Z: Unknown abbreviation
36013KT: Unknown abbreviation
9SM: Unknown abbreviation
-RAB5: light rain began at time 5 minutes after the top of the last hour
FEW018: Unknown abbreviation
BKN030: Unknown abbreviation
OVC042: Unknown abbreviation
M03/M07: Unknown abbreviation
A3035: Unknown abbreviation
RMK: Unknown abbreviation
AO2: Unknown abbreviation
SLP288: Unknown abbreviation

Related Solutions

Project flow and Report Format The following information must be included in your report: Abstract Table...
Project flow and Report Format The following information must be included in your report: Abstract Table of Content List of Figures List of Tables LIST OF ABBREVIATIONS Part 1: Introduction Part 2: Literature Review Part 3: Methodology Part 4: Result and Discussion Part 5: Conclusions Part 6: References Appendix
Describe the process and content of reporting information to nurses: Discuss how this type of report...
Describe the process and content of reporting information to nurses: Discuss how this type of report differs from communicating to other members of the healthcare team
Do you think Creative Accounting can be used to enhance reporting of financial information to report...
Do you think Creative Accounting can be used to enhance reporting of financial information to report users or is it simply a part of fraudulent accounting behaviour?   
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT