import java.util.*;

class program {
	
  static int count;
  static Rabbit[] farm;

  public static boolean choose_father()
  {
     boolean sex= false;
     boolean mature= false;
     boolean color = false;
     
     while (mature && sex)
     {
        /*int r = Random.nextInt(count);*/
        int r = 0;
        mature = farm[r].age > 0;
        sex = farm[r].sex;
        color = farm[r].color;
     }
      
  	 return color;
  	
  }
  
  
  public static int yearpassed(int count_males, long r_kill) 
  {
  	
  	int newcount = count;
  	boolean able = (count_males != 0);
  	boolean father_color;
  	
  	for(int r=0; r<count; r++) {
  		if (r == r_kill) 
  		{
  			if (farm[r].sex) --count_males;
  			farm[r].kill();
  		}
  		father_color = choose_father();
  		Rabbit tmp=farm[r].yearpassed(able, father_color);
  		if((tmp != null)) 
  		{
  			farm[newcount] = tmp;
  			if (farm[newcount].sex) ++count_males;
  			newcount++;
  	    }
  	}
    count = newcount;
  	return count_males;
  }	

  public static int countfarm() {
  	
  	int farmc=0;
  	for(int r=0; r < count; r++) {
  		if( farm[r].alive ) farmc++;
    }
  	
  	return farmc;
  }	

  public static int count_whites()
  {
  	
  	int whites = 0;
  	
  	for (int r= 0; r< count; r++)
  	{
  		if (farm[r].alive)
  		{
  		   if (farm[r].color) whites++;
  	    }
  	
  	}
  	
  	return whites; 
  }

  public static int count_blacks()
  {
  	
  	int blacks = 0;
  	for (int r= 0; r< count; r++)
  	{
  		if (farm[r].alive)
  		{
  		   if (!farm[r].color) blacks++;
  	    }
  	
  	}
  	return blacks;
  }

  public static void main(String[] args) {

	farm = new Rabbit[1000];
	int count_male = 0;
	int count_males= 1;
	
	count = 2;
	farm[0] = new Rabbit(true, true);
	farm[1] = new Rabbit(false, false);
    
    for(int i=0; i<5; i++) 
    {
    	long r_kill = Math.round(Math.random()* 10);
    	if (i == 0) yearpassed(0, -1);
        else count_males = yearpassed(count_males, r_kill);
	    System.out.print( (i+1) +  " years: " + countfarm()+" inhabitants: ");
	    System.out.print(count_blacks() + " blacks and ");
	    System.out.println (count_whites()+" whites");
	}
	System.out.println("There are "+count_males+" males in the farm.");   
  }
	
	
}