The problem here seems to be with the first, last and middles names. Please sort this out with me. Thanks. You can just go straight to the solution class
package com.codegym.task.task19.task1904;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Scanner;
/*
Yet another adapter
*/
public class Solution {
public static void main(String[] args) throws IOException {
}
public static class PersonScannerAdapter implements PersonScanner {
private final Scanner fileScanner;
public PersonScannerAdapter(Scanner fileScanner) {
this.fileScanner = fileScanner;
}
@Override
public Person read() throws IOException {
String pInfo = fileScanner.nextLine(); //person information
String lastName = pInfo.substring(0, pInfo.indexOf(' '));
pInfo = pInfo.substring(lastName.length()+1);
String firstName = pInfo.substring(0, pInfo.indexOf(' '));
pInfo = pInfo.substring(firstName.length()+1);
String middleName = pInfo.substring(0, pInfo.indexOf(' '));
String birthDay = pInfo.substring(middleName.length()+1);
Date date = new Date();
try { date = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH).parse(birthDay); }
catch (ParseException e) { System.out.println("ParseException was caught: " + e.getMessage()); }
return new Person(lastName, firstName, middleName, date);
}
@Override
public void close() throws IOException {
fileScanner.close();
}
}
}