Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.time.LocalDate;
- import java.util.Scanner;
- public class hmwk02 {
- public static void main(String[] args) {
- Scanner input = openFile("input.txt");
- int pairsProcessed;
- pairsProcessed = processDates(input);
- input.close();
- System.out.println("\nPairs Processed: " + pairsProcessed);
- System.out.println(makeDate("2/10/2019"));
- }
- public static LocalDate makeDate (String fullDate){
- LocalDate date = null;
- String parts [] = fullDate.split("/");
- int theMonth = Integer.parseInt(parts[0]);
- int theDay = Integer.parseInt(parts[1]);
- int theYear = Integer.parseInt(parts[2]);
- date = LocalDate.of(2018,9,18);
- return date;
- }
- public static int processDates(Scanner input) {
- int count = 0;
- while (input.hasNextLine()) {
- String line = input.nextLine();
- String[] parts = line.split(":");
- LocalDate a = makeDate(parts[0]);
- LocalDate b = makeDate(parts[1]);
- if(parts.length==2)
- count++;
- System.out.println(LocalDate a.compareTo(LocalDate b)>0);
- }
- return count;
- }
- public static Scanner openFile(String fileName){
- Scanner input = null;
- try {
- input = new Scanner(new File(fileName));
- } catch (FileNotFoundException e){
- System.err.println("Error: Could not open file " + fileName);
- System.exit(1);
- }
- return input;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment