Всем доброго!
Валидатор пишет: "Убедись, что метод read() корректно считывает Фамилию, Имя и Отчество с файла и устанавливает их значения в объект типа Person."
Вроде все сделал как надо-но не проходит...Любому совету буду рад!
package com.javarush.task.task19.task1904;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Scanner;
/*
И еще один адаптер
*/
public class Solution {
public static void main(String[] args) {
}
public static class PersonScannerAdapter implements PersonScanner {
private Scanner fileScanner;
PersonScannerAdapter(Scanner fileScanner)
{
this.fileScanner = fileScanner;
}
@Override
public Person read() throws IOException {
//Иванов Иван Иванович 31 12 1950 - просто памятка как должно выглядеть
String s = fileScanner.nextLine();
int counter =0;
String firstName = null;;
String middleName = null;
String lastName = null;;
String birthDate=null;
Date output =null;
ArrayList<Integer> list = new ArrayList<>();
for (int i=0; i<s.length(); i++ )
{
s.substring(i, i+1);
if (s.equals(" "))
{
list.add(i);
}
}
for (int j=0; j<list.size(); j++)
{
if (counter!=3)
{
String names = (s.substring(j, j + 1)).trim();
counter = counter + 1;
if (counter == 1) {
lastName = names;
} else if (counter == 2) {
firstName = names;
} else if (counter == 3) {
middleName = names;
}
}
else
{
String names = (s.substring(j, list.size())).trim();
birthDate = names;
//Иванов Иван Иванович 31 12 1950 - просто памятка как должно выглядеть
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd mm yyyy");
try {
output = simpleDateFormat.parse(birthDate);
}
catch (Exception e)
{
}
}
}
return new Person(lastName, firstName, middleName, output);
}
@Override
public void close() throws IOException {
this.fileScanner.close();
}
}
}