So I have met all of the requirements. But I keep getting this verification notification:
Be sure that the PEOPLE field's type argument is <Person>.
But my PEOPLE is Person, so I don't get what the issue is.
Then it also says:
Be sure that names are correctly added from the file to the PEOPLE list.
The program should properly handle hyphenated names, such as Mary-Jo.
I have checked all variations of names including hyphenated names.
So I also don't understand the issue here.
package com.codegym.task.task19.task1921;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
/*
John Johnson
*/
public class Solution {
public static final List<Person> PEOPLE = new ArrayList<>();
public static void main(String[] args) throws Exception {
BufferedReader re = new BufferedReader(new FileReader(args[0]));
//BufferedReader re = new BufferedReader(new FileReader("C:\\Users\\Alfred\\Documents\\CodeGym Data Files for exercizes\\data.txt"));
ArrayList<String> buf = new ArrayList();
while(re.ready()){
buf.add(re.readLine());
}
re.close();
for (String line :buf) {
String[] parts = line.split(" ");
int year = Integer.parseInt(parts[parts.length-1]);
int day = Integer.parseInt(parts[parts.length-2]);
int month = Integer.parseInt(parts[parts.length-3]);
StringBuilder nmBuilder = new StringBuilder();
for (int i = 0; i < parts.length-3;i++){
nmBuilder.append(parts[i]+" ");
}
String name = nmBuilder.toString().trim();
PEOPLE.add(new Person(name,month,day,year));
}
/*
for (Person p : PEOPLE) {
System.out.println("|"+p.name+"| |"+p.month+"| |"+p.day+"| |"+p.year+"|");
}
*/
}
public static class Person{
String name;
int month;
int day;
int year;
public Person(String name,int month,int day,int year){
this.name = name;
this.month = month;
this.day = day;
this.year = year;
}
}
}