import java.util.Random;

public class PeopleAccessor
{
    public Person[][] makeGrid()
    {
	int r;
	int c;
	Random aGenerator = new Random();
	Person [][] grid = new Person[2][3];  // Creates 2D array, elements are null
	for (r = 0; r < 2; r++)
	{
	    for (c = 0; c < 3; c++)
	    {
		grid[r][c] = new Person(); // Create object, element contains address of object
		grid[r][c].setAge(aGenerator.nextInt(115));
	    }
	}
	return(grid);
    }

    public void display(Person [][] grid)
    {
	int r;
	int c;
	for (r = 0; r < 2; r++)
	{
	    // printing contents of one row
	    for (c = 0; c < 3; c++)
	    {
		//print(): so all elements of one row all on same line
		System.out.print(grid[r][c].getAge() + " ");
	    }
	    // Whole displayed, move cursor to next line
	    System.out.println();
	}

    }

    public Person[][] deleteAll(Person [][] grid)
    {
	int r;
	int c;
	for (r = 0; r < 2; r++)
	{
	    for (c = 0; c < 3; c++)
	    {
		// Manually remove reference between each element-object
		grid[r][c] = null;
	    }
	}
	// Remove whole array (each element is null)
	grid = null;
	return(grid);
    }
}