I'm trying to make a program that has an array of Person objects called "personArray" that is populated by a for loop that reads user input for three separate variables and then turns those variables into a Person object and adds it to the array.
Here is my code for Person.java:
public class Person
{
private String firstName, lastName;
private int zip;
public Person(String fName, String lName, int perZip)
{
firstName = fName;
lastName = lName;
zip = perZip;
}
}
And here is my code for PersonDriver.java:
import java.util.Scanner;
public class PersonDriver
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String firstName, lastName;
int zipCode;
Person[] personArray = new Person[25];
for (int i = 0; i < 25; i++)
{
System.out.println("Enter first name: ");
firstName = scan.nextLine();
System.out.println("Enter last name: ");
lastName = scan.nextLine();
System.out.println("Enter zip: ");
zipCode = scan.nextInt();
personArray[i] = new Person(firstName, lastName, zipCode);
}
scan.close();
System.out.println(personArray);
}
}