Need help!
package com.codegym.task.task14.task1408;
/*
Chicken factory
The method must return a string as follows:
<parent class>.getDescription() + "I come from <continent>. I lay <n> eggs a month."
where <continent> is the name of the continent
and <n> is the number of eggs per month
*/
public class Solution {
public static void main(String[] args) {
Hen hen = HenFactory.getHen(Continent.AFRICA);
hen.getMonthlyEggCount();
}
static class HenFactory {
static Hen getHen(String continent) {
Hen hen = null;
if(continent.equals("NorthAmerica"))
{
return new NorthAmericanHen();
}
else if(continent.equals("Europe"))
{
return new EuropeanHen();
}
else if(continent.equals("Asia"))
{
return new AsianHen();
}
else if(continent.equals("Africa"))
{
return new AfricanHen();
}
return hen;
}
}
static abstract class Hen {
abstract int getMonthlyEggCount();
public static String getDescription(){
return "I am a chicken.";
}
}
static class NorthAmericanHen extends Hen {
final static int eggCount = 100;
public int getMonthlyEggCount(){
return eggCount;
}
public static String getDescription(){
return Hen.getDescription()+"I come from NorthAmerica. I lay "+new NorthAmericanHen().getMonthlyEggCount()+" eggs a month.";
}
}
public static class EuropeanHen extends Hen {
final static int eggCount = 120;
public int getMonthlyEggCount(){
return eggCount;
}
public static String getDescription(){
return Hen.getDescription()+"I come from Europe. I lay "+new EuropeanHen().getMonthlyEggCount()+" eggs a month.";
}
}
public static class AsianHen extends Hen {
final static int eggCount = 150;
public int getMonthlyEggCount(){
return eggCount;
}
public static String getDescription(){
return Hen.getDescription()+"I come from Asia. I lay "+new AsianHen().getMonthlyEggCount()+" eggs a month.";
}
}
public static class AfricanHen extends Hen {
final static int eggCount = 140;
public int getMonthlyEggCount(){
return eggCount;
}
public static String getDescription(){
return Hen.getDescription()+"I come from Africa. I lay "+new AfricanHen().getMonthlyEggCount()+" eggs a month.";
}
}
}