Validation says this :
The Hen class must have a getMonthlyEggCount method.
The Hen class must have a getDescription method.
The AsianHen class must be in a separate file.
The AfricanHen class's getMonthlyEggCount method must return an int.
The description of an AfricanHen should have the following format: <parent class>.getDescription() + " I come from Africa. I lay <n> eggs a month.", where <n> is the number of eggs per month (returned by the getMonthlyEggCount method. For example: I am a chicken. I come from Africa. I lay 5 eggs a month.
Be sure that the Solution.HenFactory class has a static Hen getHen(String continent) method.
package com.codegym.task.task14.task1408;
/*
Chicken factory
*/
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(Continent.AFRICA))
{
hen = new AfricanHen();
}
else if(continent.equals(Continent.NORTHAMERICA))
{
hen = new NorthAmericanHen();
}
else if(continent.equals(Continent.EUROPE)){
hen = new EuropeanHen();
}
else if(continent.equals(Continent.ASIA)){
hen = new AsianHen();
}
return hen;
}
}
static abstract class Hen {
abstract int getMonthlyEggCount();
String getDescription(){
return "I am a chicken";
}
}
static class NorthAmericanHen extends Hen{
@Override
int getMonthlyEggCount() {
return 4;
}
@Override
String getDescription() {
return (super.getDescription()+ " "+"I come from "+Continent.NORTHAMERICA+". I lay " + getMonthlyEggCount()+ " eggs a month.");
}
}
static class EuropeanHen extends Hen {
@Override
int getMonthlyEggCount() {
return 4;
}
@Override
String getDescription() {
return (super.getDescription()+ " "+"I come from "+Continent.EUROPE+". I lay " + getMonthlyEggCount()+ " eggs a month.");
}
}
static class AsianHen extends Hen {
@Override
int getMonthlyEggCount() {
return 4;
}
@Override
String getDescription() {
return (super.getDescription()+ " "+"I come from "+Continent.ASIA+". I lay " + getMonthlyEggCount()+ " eggs a month.");
}
}
static class AfricanHen extends Hen {
@Override
int getMonthlyEggCount() {
return 4;
}
@Override
String getDescription() {
return (super.getDescription()+ " "+"I come from " + Continent.AFRICA+". I lay " + getMonthlyEggCount()+ " eggs a month.");
}
}
}