Hi, according to the validator there is a problem with reading the first, middle and last name and storing it int the Person object. I tried to play with different configurations but without any luck.
Any help appreciated ^^
package com.codegym.task.task19.task1904;
import java.io.FileInputStream;
import java.io.IOException;
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) {
}
//. The PersonScannerAdapter class must implement the PersonScanner interface
// The PersonScannerAdapter class must implement the PersonScanner interface.
//3. The PersonScannerAdapter class must have a private Scanner field called fileScanner.
//4. The PersonScannerAdapter class must have a constructor with a Scanner parameter.
//5. The PersonScannerAdapter class's close() method must delegate the call to fileScanner.
public static class PersonScannerAdapter implements PersonScanner {
private Scanner fileScanner;
public PersonScannerAdapter(Scanner fileScanner){
this.fileScanner = fileScanner;
}
//The PersonScannerAdapter class's read() method should read a line from the file, parse it,
//and return only one person's data as an Person object.
@Override
public Person read() throws IOException{
String info = fileScanner.nextLine(); //reads line;
String[] personInfo = info.split(" ");//splits String into multiple Strings and return an array which contains the split Strings
String firstName = personInfo[0];
String middleName = personInfo[1];
String lastName = personInfo[2];
String month = personInfo[3];
String day = personInfo[4];
String year = personInfo[5];
Date date =null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM dd yyyy",Locale.ENGLISH);
try{
date = simpleDateFormat.parse(month+day+ year);
}catch(ParseException e){}
Person person = new Person(firstName,middleName,lastName, date);
return person;
}
@Override
public void close() throws IOException {
fileScanner.close();
}
}
}