Answer:
Kindly go to the explanation for the answer.
Explanation:
Person.java
public class Person{
private String firstName, lastName;
private int zip;
public Person(String firstName, String lastName, int zip) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.zip = zip;
}
public String toString() {
String line = "\tFirst Name = " + this.firstName + "\n\tLast Name = " + this.lastName;
line += "\n\tZip Code = " + this.zip + "\n";
return line;
}
}
Test.java
import java.util.ArrayList;
import java.util.Scanner;
public class Test{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
ArrayList<Person> al = new ArrayList<Person>();
for(int i = 0; i < 25; i++) {
System.out.print("Enter person details: ");
String line = in.nextLine();
String words[] = line.split("\t");
String fname = words[0];
String lname = words[1];
int numb = Integer.parseInt(words[2]);
Person p = new Person(fname, lname, numb);
al.add(p);
}
for(int i = 0; i < 25; i++) {
System.out.println("Person " + (i + 1) + ":");
System.out.println(al.get(i));
}
}
}