Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java The Person class contains the following constructor: /** constructs a perso

ID: 3883967 • Letter: J

Question

Java

The Person class contains the following constructor:

/** constructs a person based on name and dob. but if the name or dob are unreasonable, it throws a BadPersonException. */

Person(String name, String dob) throws BadPersonException

Complete the following static method of some class X:

/** pre: f's file is readable and contains at least 2 hunks on each line

post: returns persons constructed using the first 2 hunks of each line as name and dob

prints lines that could not be used to construct a person. */

static ArrayList getPeople(File f){

Explanation / Answer

static ArrayList getPeople(File f) throws FileNotFoundException, IOException{
BufferedReader br = new BufferedReader(new FileReader(f));
String str;
//List to store the persons
ArrayList<Person> pList = new ArrayList();
//Read the file
while((str=br.readLine())!=null){
//Parse name and dob
String details[] = str.trim().split(" ");
String name = details[0];
String dob = details[1];
try {
//Create an object
Person person = new Person(name,dob);
//add the object to the list
pList.add(person);
} catch (BadPersonException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
return pList;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote