Won't compile.
IDEA says the different Hen classes should be static.
When I make the classes static the code copiles but none of the conditions are met.
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;
//write your code here
if (continent.equals(Continent.NORTHAMERICA))
hen = new NorthAmericanHen();
else if (continent.equals(Continent.AFRICA))
hen = new AfricanHen();
else if (continent.equals(Continent.ASIA))
hen = new AsianHen();
else if (continent.equals(Continent.EUROPE))
hen = new EuropeanHen();
return hen;
}
}
public interface Continent {
String NORTHAMERICA = "NorthAmerica";
String AFRICA = "Africa";
String ASIA = "Asia";
String EUROPE = "Europe";
}
public abstract class Hen {
public abstract int getMonthlyEggCount();
public String getDescribtion() {
return "I am a Chicken";
}
}
public class NorthAmericanHen extends Hen {
public int getMonthlyEggCount() {
return 1;
}
public String getDescribtion() {
return super.getDescribtion() + " I come from " + Continent.NORTHAMERICA + ". I lay " + this.getMonthlyEggCount() + " eggs a month.";
}
}
public class EuropeanHen extends Hen {
public int getMonthlyEggCount() {
return 2;
}
public String getDescribtion() {
return super.getDescribtion() + " I come from " + Continent.EUROPE + ". I lay " + this.getMonthlyEggCount() + " eggs a month.";
}
}
public class AsianHen extends Hen {
public int getMonthlyEggCount() {
return 3;
}
public String getDescribtion() {
return super.getDescribtion() + " I come from " + Continent.ASIA + ". I lay " + this.getMonthlyEggCount() + " eggs a month.";
}
}
public class AfricanHen extends Hen {
public int getMonthlyEggCount() {
return 4;
}
public String getDescribtion() {
return super.getDescribtion() + " I come from " + Continent.AFRICA + ". I lay " + this.getMonthlyEggCount() + " eggs a month.";
}
}
}