Please help !
package pl.codegym.task.task19.task1904;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
/*
Jeszcze jeden adapter
*/
public class Solution {
public static void main(String[] args) throws IOException, ParseException {
Scanner scanner = new Scanner(System.in);
PersonScannerAdapter personScannerAdapter = new PersonScannerAdapter(scanner);
System.out.println(personScannerAdapter.read());
personScannerAdapter.close();
}
public static class PersonScannerAdapter implements PersonScanner
{
private Scanner fileScanner;
public PersonScannerAdapter(Scanner fileScanner) throws FileNotFoundException {
this.fileScanner = fileScanner;
}
@Override
public Person read() throws IOException, ParseException {
BufferedReader file = new BufferedReader(new FileReader(fileScanner.nextLine()));
/// when we want to be able to choose a person
// List<String> list = new ArrayList<>();
// while (file.ready())
// {
// list.add(file.readLine());
// }
String firstName;
String lastName;
String middleName;
Date birthDate;
Person person = null;
while (file.ready()) { // - <--
String line = file.readLine(); // + < String line = list.get(0);
String[] tab = line.split(" ");
firstName = tab[0];
lastName = tab[2];
middleName = tab[1];
String daFo = tab[5] + "." + tab[3] + "." + tab[4];
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd");
birthDate = simpleDateFormat.parse(daFo);
person = new Person(lastName, firstName, middleName, birthDate);
}
file.close();
return person;
}
@Override
public void close() throws IOException {
fileScanner.close();
}
}
}