I've tried a bunch of different things but can't get my read method to work correctly, not sure why.
package com.codegym.task.task19.task1904;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.Scanner;
import java.util.Date;
/*
Yet another adapter
*/
public class Solution {
public static void main(String[] args) {
}
public static class PersonScannerAdapter implements PersonScanner {
private final Scanner fileScanner;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM dd yyyy",Locale.ENGLISH);
Date birthDate;
public PersonScannerAdapter(Scanner fileScanner) {
this.fileScanner = fileScanner;
}
@Override
public Person read() throws IOException {
String line = fileScanner.nextLine();
String [] parsedLine = line.split(" ");
Person person;
String firstName = parsedLine[0];
String middleName = parsedLine[1];
String lastName = parsedLine[2];
String month = parsedLine[3];
String day = parsedLine[4];
String year = parsedLine[5];
try {
birthDate = simpleDateFormat.parse(month+" "+day+" "+year);
}catch (ParseException e){
}
person = new Person(firstName,middleName,lastName,birthDate);
return person;
}
@Override
public void close() throws IOException {
fileScanner.close();
}
}
}