import java.io.*;
import java.util.*;

/**
 * The Siblings class reads in a file with Sibling ages and finds 
 *   the average age of the siblings
 * 
 * @author Kathryn McKinley
 * @version March 2007
 */
public class Siblings
{
    // Array of ages
    private int[][] ages;
    private float averageAges;
    private float averageNumber;

    /**
     * Constructor for objects of class Siblings
     */
    public Siblings()
    {
        // Centinel value indicating we have not computed the age yet
        averageAges = -1;
        averageNumber = -1;
        
    }

    /**
     * Compute average of ages
     * 
     */
    public float averageAge()
    {
        return 0;
    }
    /**
     * Compute average of number of siblings
     * 
     */
    public float averageNum()
    {
        float ave = 0;
        
        for (int i = 0; i < ages.length; i++) {
            ave+= ages[i].length;
        }
        return ave/ages.length;
    }   /**
     * Reads in the ages from a file
     */
    public void readAges(Scanner sFile)
    {
        // What file format do we want?
        /* File format: 
         *   <# n students> 
         *   <# siblings s1> <list of ages>
         *   ...
         *   <# siblings sn> <list of ages>
         */
        int numStuds = sFile.nextInt();
        ages = new int[numStuds][];
        int j;
        
        for (int i = 0; i < numStuds; i++) {
            j = sFile.nextInt();
            ages[i] = new int[j];
            for (int k = 0; k < j; k++) {
                ages[i][k] = sFile.nextInt();
            }
        }
        
        
        
    }
    /**
     * Print out all the ages we read in
     */ 
    public void printAges()
    {
        System.out.println("The ages of siblings of 305j student are:");
        for (int i = 0; i < ages.length; i++) {
            for (int j = 0; j < ages[i].length; j++) {
                System.out.print(ages[i][j] + " ");
            }
            System.out.println();
        }
              
        
    }
        
    public static void main(String[] args) throws Exception
    {
        Scanner stdin = new Scanner (System.in);
        Scanner sFile = null;
        File f = null;
        
        while (sFile == null) {
            try {
                System.out.print("Enter the input file name: ");
                f = new File(stdin.nextLine());
                sFile = new Scanner(f);
            } catch (FileNotFoundException e) {
                System.out.println("File not found.");   
            }
        }
        Siblings sibs = new Siblings();
        sibs.readAges(sFile);
        sibs.printAges();
        System.out.println("Average number of siblings: " + sibs.averageNum());
    }
}
