First of all, yes I know I added code but that was just to illustrate that the code works like it's supposed to. Here's the output I get:
25
I am a chicken. I come from Africa. I lay 25 eggs a month.
15
I am a chicken. I come from North America. I lay 15 eggs a month.
12
I am a chicken. I come from Europe. I lay 12 eggs a month.
30
I am a chicken. I come from Asia. I lay 30 eggs a month.
I have the same problem whether I declare the number of eggs in the method only or if I declare a variable and have the method return the this.variable.
Can someone copy and paste the answer please? Over it.
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();
System.out.println(hen.getMonthlyEggCount());
System.out.println(hen.getDescription());
Hen hen1 = HenFactory.getHen(Continent.NORTHAMERICA);
hen.getMonthlyEggCount();
System.out.println(hen1.getMonthlyEggCount());
System.out.println(hen1.getDescription());
Hen hen2 = HenFactory.getHen(Continent.EUROPE);
hen.getMonthlyEggCount();
System.out.println(hen2.getMonthlyEggCount());
System.out.println(hen2.getDescription());
Hen hen3 = HenFactory.getHen(Continent.ASIA);
hen.getMonthlyEggCount();
System.out.println(hen3.getMonthlyEggCount());
System.out.println(hen3.getDescription());
}
static class HenFactory {
static Hen getHen(String continent) {
Hen hen = null;
switch (continent) {
case Continent.NORTHAMERICA:
hen = new NorthAmericanHen(Continent.NORTHAMERICA);
break;
case Continent.AFRICA:
hen = new AfricanHen(Continent.AFRICA);
break;
case Continent.EUROPE:
hen = new EuropeanHen(Continent.EUROPE);
break;
case Continent.ASIA:
hen = new AsianHen(Continent.ASIA);
break;
default:
return null;
}
return hen;
}
}
}