Luninariel

Homework 2

Sep 15th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.time.LocalDate;
  4. import java.util.Scanner;
  5.  
  6. public class hmwk02 {
  7.     public static void main(String[] args) {
  8.         Scanner input = openFile("input.txt");
  9.         int pairsProcessed;
  10.         pairsProcessed = processDates(input);
  11.         input.close();
  12.         System.out.println("\nPairs Processed: " + pairsProcessed);
  13.         System.out.println(makeDate("2/10/2019"));
  14.  
  15.  
  16.  
  17.     }
  18.     public static LocalDate makeDate (String fullDate){
  19.         LocalDate date = null;
  20.         String parts [] = fullDate.split("/");
  21.         int theMonth = Integer.parseInt(parts[0]);
  22.         int theDay = Integer.parseInt(parts[1]);
  23.         int theYear = Integer.parseInt(parts[2]);
  24.         date = LocalDate.of(2018,9,18);
  25.  
  26.  
  27.         return date;
  28.     }
  29.     public static int processDates(Scanner input) {
  30.         int count = 0;
  31.  
  32.         while (input.hasNextLine()) {
  33.             String line = input.nextLine();
  34.             String[] parts = line.split(":");
  35.             LocalDate a = makeDate(parts[0]);
  36.             LocalDate b = makeDate(parts[1]);
  37.         if(parts.length==2)
  38.             count++;
  39.         System.out.println(LocalDate a.compareTo(LocalDate b)>0);
  40.  
  41.  
  42.     }
  43.         return count;
  44.         }
  45.  
  46.     public static Scanner openFile(String fileName){
  47.         Scanner input = null;
  48.  
  49.         try {
  50.             input = new Scanner(new File(fileName));
  51.         } catch (FileNotFoundException e){
  52.             System.err.println("Error: Could not open file " + fileName);
  53.             System.exit(1);
  54.         }
  55.         return input;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment