Stuck with run time errors: non-static variable this cannot be referenced from a static context.
Nee some help!
package com.codegym.task.task14.task1408;
/*
Chicken factory
*/
public class Solution {
public static void main(String[] args) {
Hen hen = HenFactory.getHen(Continent.AFRICA);
System.out.println(hen.getMonthlyEggCount());
System.out.println(hen.getDescription());
}
static class HenFactory {
static Hen getHen(String continent) {
Hen hen = null;
//write your code here
if (continent.equalsIgnoreCase("northamerica")) {
hen = new NorthAmericanHen();
} else if (continent.equalsIgnoreCase("europe")) {
hen = new EuropeanHen();
} else if (continent.equalsIgnoreCase("asia")) {
hen = new AsianHen();
} else if (continent.equalsIgnoreCase("africa")) {
hen = new AfricanHen();
}
return hen;
}
}
public class NorthAmericanHen extends Hen{
int eggCount = 25;
@Override
public int getMonthlyEggCount() {return eggCount;}
@Override
public String getDescription() {
String result = super.getDescription() + " I come from NorthAmerica. I lay " + getMonthlyEggCount() + " eggs a month.";
return result;
}
}
public class EuropeanHen extends Hen{
int eggCount = 25;
@Override
public int getMonthlyEggCount() {return eggCount;}
@Override
public String getDescription() {
String result = super.getDescription() + " I come from Europe. I lay " + getMonthlyEggCount() + " eggs a month.";
return result;
}
}
class AsianHen extends Hen{
int eggCount = 25;
@Override
public int getMonthlyEggCount() {return eggCount;}
@Override
public String getDescription() {
String result = super.getDescription() + " I come from Asia. I lay " + getMonthlyEggCount() + " eggs a month.";
return result;
}
}
class AfricanHen extends Hen{
int eggCount = 25;
@Override
public int getMonthlyEggCount() {return eggCount;}
@Override
public String getDescription() {
String result = super.getDescription() + " I come from Africa. I lay " + getMonthlyEggCount() + " eggs a month.";
return result;
}
}
}