package com.codegym.task.task14.task1408;
/*
Chicken factory
*/
public class Solution {
public static void main(String[] args) {
Hen hen = HenFactory.getHen(Continent.NORTHAMERICA);
hen.getMonthlyEggCount();
//System.out.println(hen.getMonthlyEggCount());
//System.out.println(hen.getDescription());
}
static class HenFactory {
static Hen getHen(String continent) {
Hen hen = null;
if (continent.equals(Continent.NORTHAMERICA)){
hen = new AmericanHen();
}
else if (continent.equals(Continent.EUROPE)){
hen = new EuropeanHen();
}
else if (continent.equals(Continent.ASIA)){
hen = new AsianHen();
}
else if (continent.equals(Continent.AFRICA)){
hen = new AfricanHen();
}
return hen;
}
}
}
I don't meet last 4 requirements, please help me :)
Resolved
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Tiko hakobyan
15 June 2020, 13:06
shouldn't line 22 in solution class contain new NorthAmericanHen() instead of new AmericanHen(); ?
0
Mike McKenna
26 May 2020, 02:09
Hi,
quite a task with files . solution.java,continent.java,hen.java Ok .
in African Hen, Asian Hen, North American Hen European Hen .
if u make following changes task should work.
line 3 remove implements Continent
line 5 return #; only
remove line 6.
remove lines 8-10 .
replace with
Hope I helped .
0
Agata
26 May 2020, 09:17
Tahnks :)
but still 4 of them are not met which really confuses me and now my code looks like this (each in different section/classes):
public class AsianHen extends Hen {
int getMonthlyEggCount(){
return 15;
}
@Override
public String getDescription(){
return super.getDescription()+" I come from "+Continent.ASIA+". I lay "+getMonthlyEggCount()+" eggs a month.";
}
}
public class AfricanHen extends Hen {
int getMonthlyEggCount(){
return 2;
}
@Override
public String getDescription(){
return super.getDescription()+" I come from "+Continent.AFRICA+". I lay "+getMonthlyEggCount()+" eggs a month.";
}
}
public class AmericanHen extends Hen {
int getMonthlyEggCount(){
return 5;
}
@Override
public String getDescription(){
return super.getDescription()+" I come from "+Continent.NORTHAMERICA+". I lay "+getMonthlyEggCount()+" eggs a month.";
}
}
public class EuropeanHen extends Hen {
int getMonthlyEggCount(){
return 10;
}
@Override
public String getDescription(){
return super.getDescription()+" I come from "+Continent.EUROPE+". I lay "+getMonthlyEggCount()+" eggs a month.";
}
}
(I didn't change anything in solution)
0