Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.2 kB
6
Indexable
Never
import java.util.Scanner;

public class DateParser {
   public static int getMonthAsInt(String monthString) {
      int monthInt;
      
      // Java switch/case statement                                                                
      switch (monthString) {
         case "January": 
            monthInt = 1; 
            break;
         case "February": 
            monthInt = 2; 
            break;
         case "March": 
            monthInt = 3; 
            break;
         case "April": 
            monthInt = 4; 
            break;
         case "May": 
            monthInt = 5; 
            break;
         case "June": 
            monthInt = 6; 
            break;
         case "July": 
            monthInt = 7; 
            break;
         case "August": 
            monthInt = 8; 
            break;
         case "September": 
            monthInt = 9; 
            break;
         case "October": 
            monthInt = 10; 
            break;
         case "November": 
            monthInt = 11; 
            break;
         case "December": 
            monthInt = 12; 
            break;
         default: 
            monthInt = 0;
      }
      
      return monthInt;
   }

   public static void main(String[] args) {
      int monthInt1 = 0;
      int dayInt = 0; 
      int yearInt = 0; 
      String myString = "this is starting length"; 
      Scanner scnr2 = null; 
     Scanner scnr = new Scanner(System.in);

      // TODO: Read dates from input, parse the dates to find the ones
      //       in the correct format, and output in m-d-yyyy format
      
      while (myString.length() > 5){
         myString = scnr.nextLine(); 
         scnr2 = new Scanner(myString);
         
         
      monthInt1 = getMonthAsInt(scnr2.next()); 
      if (  monthInt1 != 0)
      {
         String testChar = scnr.next(); 
         if (Character.isDigit(testChar.charAt(0)))
         {
               dayInt = testChar.charAt(0) - '0';   
            // if (testChar.charAt(1) == ',') 
          //   {
              yearInt = scnr2.nextInt(); 
               System.out.println (monthInt1 + "-" + dayInt + "-" + yearInt); 
          //   }
         } 
       }
      }  
   }
}