Design and implement an application name the driver class Pa
Solution
Hi friend please find my code.
Input file contains:
each line: first_name last_name zip_code
Note: zip_code shoud be of type integer
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class PersonObjectProgram {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// asking for input file name
System.out.print(\"Enter input filename: \");
String fileName = sc.next();
// opening input file name
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
// creating Array to Store Person Object
Person[] persons = new Person[25];
String line;
int index = 0;
while(((line = br.readLine()) != null) && index<25){
// splitting line by space
// if empty line, then stop
if(line.trim().equals(\"\") || line.trim().isEmpty())
break;
String[] temp = line.split(\"\\\\s+\");
// creating a person object
Person p = new Person();
p.setFirstName(temp[0]); // first element of temp array : first name
p.setLastName(temp[1]);
p.setZipCode(Integer.parseInt(temp[2].trim()));
// adding in array list
persons[index++] = p;
}
//closing file
br.close();
fr.close();
// printing array list
for(Person p : persons){
System.out.println(p.toString());
}
}
}

