Guest User

Untitled

a guest
Jan 9th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class metarAbbrev {
  4.  
  5.     public static void main(String[] args) {
  6.         // Create a scanner to take an input
  7.         // Use nextLine () to read the next line of input, and save it
  8.    
  9.         Scanner in = new Scanner(System.in);
  10.         System.out.print("Enter a METAR abbreviation: ");
  11.         String abbreviation = in.nextLine( ).toUpperCase();
  12.        
  13.         // Declare and initialize meaning
  14.         String meaning = "";
  15.         boolean meaningPrint = true;
  16.        
  17.         // Use switch statements to check for valid abbreviation inputs
  18.         // Then set the meaning of accordingly based on the abbreviation
  19.         switch (abbreviation) {
  20.             case  "+" :
  21.                 meaning = "heavy intensity";
  22.                 break;
  23.             case  "-" :
  24.                 meaning = "low intensity";
  25.                 break;
  26.             case  "B" :
  27.                 meaning = "began at time";
  28.                 break;
  29.             case  "E" :
  30.                 meaning = "ended at time";
  31.                 break;
  32.             case  "RA" :
  33.                 meaning = "rain";
  34.                 break;
  35.             case  "DZ" :
  36.                 meaning = "drizzle";
  37.                 break;
  38.             case  "HZ" :
  39.                 meaning = "haze";
  40.                 break;
  41.             case  "SN" :
  42.                 meaning = "snow";
  43.                 break;
  44.             default :
  45.                 System.out.println("Unknown abbreviation"); // If none of the above cases occur, output this
  46.                 meaningPrint = false;
  47.         }
  48.         if (meaningPrint == true) {
  49.             System.out.println("The abbreviation means " + meaning);
  50.         }
  51.         in.close( ); // Closes the Scanner
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment