I don't see where the problem is. Validator is telling me to "Be sure that names are correctly added from the file to the PEOPLE list." But I've run a loop on PEOPLE and all the names are in there as they should.
Any hint?
Thanks!
package com.codegym.task.task19.task1921;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/*
John Johnson
*/
public class Solution {
public static final List<Person> PEOPLE = new ArrayList<>();
public static void main(String[] args) throws IOException, ParseException {
String fileName = args[0];
// String fileName = "/home/jesus/Desktop/1.txt";
BufferedReader fileReader = new BufferedReader(new FileReader(fileName));
String line;
ArrayList<String[]> lines = new ArrayList<>();
while ((line = fileReader.readLine()) != null) {
lines.add(line.split(" "));
}
fileReader.close();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM dd yyyy");
String dateInString;
Date birthDay;
int month;
int day;
int year;
for (int i = 0; i < lines.size(); i++) {
String[] currentLine = lines.get(i);
int length = currentLine.length;
// get name
StringBuilder fullName = new StringBuilder();
int nameCounter = 0;
while (nameCounter < length - 3) {
fullName.append(currentLine[nameCounter] + " ");
nameCounter++;
}
// create date
month = Integer.parseInt(currentLine[length - 3]);
day = Integer.parseInt(currentLine[length - 2]);
year = Integer.parseInt(currentLine[length - 1]);
dateInString = month + " " + day + " " + year;
birthDay = simpleDateFormat.parse(dateInString);
// add new person
PEOPLE.add(new Person(fullName.toString(), birthDay));
}
for(Person person : PEOPLE) {
System.out.println(person.getName() + " " + person.getBirthDate());
}
}
}