import java.io.*;
// import java.util.Scanner;
// import java.util.LinkedList ;
// import java.util.Iterator ;
import java.util.* ;

public class ScanCatsAndDogs {
  
   public static LinkedList<Dog> dogs = new LinkedList<Dog>() ;
   public static LinkedList<Cat> cats = new LinkedList<Cat>() ;
   public static LinkedList<Cat> oldCats = new LinkedList<Cat>() ;
   
   
   public static void ReadInDogs() throws IOException 
   {
        Scanner s = null;
        
        String tempName = "" ;
        int tempAge  = 0 ;
        int tempLevel = 0 ;
        int count = 0;
        int tempId = 0 ;
        
        Dog aDog ;
        Cat aCat ;
        int numCats ;
        
        // Random rNumGenerator = new Random() ;
        try 
        {
            s = new Scanner(new BufferedReader(new FileReader("dogs.txt")));

            while (s.hasNext()) 
            {
              
              if (count == 0) { tempName = s.next() ; }
              if (count == 1) {tempId =  Integer.parseInt ( s.next()  ) ; }
              if (count == 2) { tempAge = Integer.parseInt ( s.next() ) ; }
              
              if (count == 3)
              {
                tempLevel =  Integer.parseInt ( s.next()  ) ;
                aDog = new Dog( tempName, tempId, tempAge, tempLevel ) ;
                dogs.add(aDog) ;
              }
              
              count = count + 1 ;
              if (count > 3)
                count = 0 ;
            }
        }
        finally 
        {
            if (s != null) { s.close(); }
        }
   }
   
   public static void ReadInCats() throws IOException 
   {
     Scanner s = null;
     int count ;
     int tempId = 0 ;
     int tempAge = 0 ;
     String tempName = "" ;
     Cat aCat ;
     
     try 
     {
            s = new Scanner(new BufferedReader(new FileReader("cats.txt")));
            
            count = 0 ;
            while (s.hasNext() )
            {
              if (count == 0) { tempName =   ( s.next()  ) ; }
              if (count == 1) { tempId =  Integer.parseInt ( s.next()  ) ; }
              if (count == 2) { 
                tempAge =  Integer.parseInt ( s.next()  ) ; 
                aCat = new Cat(tempName, tempId, tempAge) ;
                cats.add( aCat ) ;
                
              }
              count++ ;
              if (count > 2)
                count = 0 ;
            }   
        }
        finally
        {
          if (s != null) { s.close(); }
        }
   }
            
               
    public static void main(String[] args) throws IOException 
    {
        
        Cat aCat ;
        Dog aDog ;
        
        ReadInDogs() ;  // populate the dogs list with dogs from the file dogs.txt
        ReadInCats() ;  // populate the cats list with cats from the file cats.txt
        
        // print out the list
        System.out.println("Printing out cat list:") ;
        Iterator i = cats.iterator() ;
        while ( i.hasNext() )
        {
              aCat =   (Cat) i.next() ;
              aCat.Print() ;
        }
        
        System.out.println("Printing out dog list:") ;
        i = dogs.iterator() ;
        while ( i.hasNext() )
        {
              aDog =   ( Dog ) i.next() ;
              aDog.Print() ;
        }
            
        System.out.println("About to separate into two lists") ;
        i = cats.iterator() ;
        while (i.hasNext() )
        {
              aCat = (Cat) i.next() ;
              // tempPerson.Print() ;
              if (aCat.getAge() > 12)
              {
                oldCats.add( aCat ) ;
              }
              
        }
        System.out.println("cats list size = " + cats.size() ) ;
        System.out.println("old cats list size = " + oldCats.size() ) ;
        System.out.println("dogs list size = " + dogs.size() ) ;
        
            
    } 
    
    
    
    
   
    
    
}