40.7k views
3 votes
In generation zero, we have one egg, no chickens, and no hens. In the nth generation, each egg from the previous generation hatches into a chicken, each chicken from the previous generation grows up into a hen, and each hen from the previous generation lays an egg. Complete the mutually recursive functions that yield the number of hens, chickens, and eggs in the nth generation

Poultry.java
1 public class Poultry
{
public static int hens(int n)
{
}
public static int chickens (int n)
{
}
public static int eggs (int n) 17
}

User DoamnaT
by
5.4k points

1 Answer

3 votes

Answer:

public class Poultry {

public static int hens(int n)

{if(n==0)

return 0;

else

return hens(n-1)+chickens(n-1);//previous generation hens+ newly generated hens from chicks

}

public static int chickens(int n)

{if(n==0)

return 0;

else

return eggs(n-1);

}

public static int eggs(int n)

{if(n==0)

return 1;

else

return hens(n-1);

}

/* public static void main(String[] args) {

System.out.println(Poultry.chickens(8));

}*/

}

Step-by-step explanation:

User Tomas Aschan
by
5.1k points