SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  import java.io.File;
  2.  import java.io.FileInputStream;
  3.  import java.io.FileOutputStream;
  4.  import java.io.IOException;
  5.  import java.util.Scanner;
  6.  
  7.  public class Proj5 {
  8.      public static void main(String[] args) throws IOException {
  9.          FileInputStream in = null;
  10.          FileOutputStream out = null;
  11.          boolean loop;
  12.  
  13.          Scanner s = new Scanner(System.in);
  14.          System.out.print("Enter name of input file: ");
  15.          String inputFile = s.nextLine();
  16.          in = new FileInputStream(inputFile);
  17.  
  18.          /*
  19.          System.out.print("Enter name of output file: ");
  20.          String outputFile = s.nextLine();
  21.          out = new FileOutputStream(outputFile);
  22.            */
  23.  
  24.          Scanner inFile = new Scanner(new File(inputFile));
  25.          int firstLine = Integer.parseInt(inFile.nextLine());
  26.          int[][] datePieces = new int[firstLine][3];
  27.  
  28.          for (int i = 0; i < firstLine; i++) { // Splits the import dates into an array
  29.              String[] tokens = inFile.nextLine().split("/");
  30.              datePieces[i][0] = Integer.parseInt(tokens[1]); // day
  31.              datePieces[i][1] = Integer.parseInt(tokens[0]); // month
  32.              datePieces[i][2] = Integer.parseInt(tokens[2]); // year
  33.          }
  34.         inFile.close();
  35.  
  36.          //do {
  37.          System.out.print("Choose a date format type:");
  38.          System.out.print("\n\t(1) DD/MM/YYYY (ex. 26/08/2019, with leading zeroes on months and days)");
  39.          System.out.print("\n\t(2) DD Mon, YYYY (ex. 26 Aug, 2019, with leading zeroes on days)");
  40.          System.out.print("\n\t(3) DOW, Month DDD, YYYY (ex. Monday, August 26, 2019, no leading zeroes)");
  41.          System.out.print("\n\t(4) Julian format, YYYYddd (where dd is day from 001-365)\n" +
  42.                  "Enter an option, 1-4:");
  43.          int choice = Integer.parseInt(s.nextLine());
  44.          if (choice == 1) {
  45.              getDD_MM_YYYY(datePieces);
  46.          } else if (choice == 2) {
  47.              getDD_Mon_YYYY(datePieces);
  48.          } else if (choice == 3) {
  49.  
  50.          } else if (choice == 4) {
  51.              getJulianFormat(datePieces);
  52.          } else {
  53.              System.out.println("Invalid Entry, Please enter a value from 1-4");
  54.              choice = Integer.parseInt(s.nextLine());
  55.          }
  56.          //} while (loop);
  57.      }// end main
  58.  
  59.      public enum DateValue {
  60.          DAY(0),
  61.          MONTH(1),
  62.          YEAR(2);
  63.          public final int label;
  64.  
  65.          private DateValue(int label) {
  66.              this.label = label;
  67.          }
  68.      } // end of enum
  69.  
  70.      public static String[] getDD_MM_YYYY(int[][] datePieces) { //OPTION 1
  71.          String day = null, month = null, year = null;
  72.  
  73.          String[] dates = new String[datePieces.length];
  74.  
  75.          for (int i = 0; i < datePieces.length; i++) {
  76.  
  77.              day = String.format("%02d", datePieces[i][DateValue.DAY.label]);
  78.              month = String.format("%02d", datePieces[i][DateValue.MONTH.label]);
  79.              year = String.format("%04d", datePieces[i][DateValue.YEAR.label]);
  80.  
  81.              dates[i] = (day + "/" + month + "/" + year);
  82.              //System.out.println(dates[i]);
  83.  
  84.          }
  85.          return dates;
  86.      } // end of getDD_MM_YYYY - option 1
  87.      public static String[] getDD_Mon_YYYY(int[][] datePieces){ // OPTION 2
  88.          String day = null, month = null, year = null;
  89.  
  90.          String[] dates = new String[datePieces.length];
  91.  
  92.          for (int i = 0; i < datePieces.length; i++) {
  93.  
  94.              day = String.format("%02d", datePieces[i][DateValue.DAY.label]);
  95.              //month = String.format("%02d", datePieces[i][DateValue.MONTH.label]);
  96.              year = String.format("%04d", datePieces[i][DateValue.YEAR.label]);
  97.              switch(datePieces[i][DateValue.MONTH.label])
  98.              {
  99.                  case  1: month = "Jan"; break;
  100.                  case  2: month = "Feb"; break;
  101.                  case  3: month = "Mar"; break;
  102.                  case  4: month = "Apr"; break;
  103.                  case  5: month = "May"; break;
  104.                  case  6: month = "Jun"; break;
  105.                  case  7: month = "Jul"; break;
  106.                  case  8: month = "Aug"; break;
  107.                  case  9: month = "Sep"; break;
  108.                  case  10: month = "Oct"; break;
  109.                  case  11: month = "Nov"; break;
  110.                  case 12: month = "Dec"; break;
  111.              }
  112.              dates[i] = (day + " " + month + ", " + year);
  113.             // System.out.println(dates[i]);
  114.  
  115.          }
  116.          return dates;
  117.      } // end of getDD_Mon_YYYY - option 2
  118.      public static String[] getJulianFormat(int[][] datePieces){
  119.      }// end of getJulianFormat - option 3
  120.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top