Chicken factory

  • 16
  • Locked
Let's create an international chicken factory. We'll fill it with chickens from all over the world. Create a list that indicates each hen's nationality and we'll track how many eggs they lay each month. How do you do that? Using abstract classes and inheritance, of course.
You can't complete this task, because you're not signed in.
Comments (16)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Олег Байбула
Level 32 , Ukraine
10 January, 10:34
Why don't we use ENUM instead of Interface? Enum has not been introduced yet?
Ryan D Vibbert
Level 26 , United States of America, UK
16 November 2022, 22:34
Not sure why they wouldn't have output of the description as part of the task. Seems pointless, I did that and got dinged initially...oh well.
Level 19 , Kyiv, Ukraine
26 July 2022, 14:08
My mistake was that I did't create a Hen class in separate file.
Justin Smith
Level 40 , Greenfield, USA, United States
6 August 2021, 21:41
This is a weird task because we do all this work to create output strings and then we never actually print anything to the screen.
Level 15 , Old Town, United States
9 June 2021, 14:45
took a while, but good learning. happy coding! :)
Michael T Schaefer
Level 15 , Columbia, United States
13 May 2021, 01:00
Why is the getDescription() from the child class called when we use the HenFactory's getHen() to declare a new variable, "hen", of Hen type when it points to one of the child class's in memory? I checked this lesson and this website and it seems to say the opposite. Can someone clarify? To review/summarize my question... does the declaration type qualify the methods available to that object? Or is its location in memory (what comes after the 'new' keyword)? I hope I'm wording all of this accurately and clearly. Still feel like a noob! : )
Vadim “迪姆哥”
Level 28 , Kazakhstan
5 December 2022, 11:20
When you execute code:
Hen chicken = new EuropeanHen();
You are creating object EuropeanHen in memory, along with it own variables, values and methods implementations. The "chicken" variable points to that new instance of EuropeanHen object. Type of "chicken" variable Hen, means that number methods available to call on this variable are the same as in Hen class. Methods that implemented only in EuropeanHen(if they exist), which are absent in Hen class, cannot be called on this "chicken" variable of Hen type. If you want make these EuropeanHen special methods available, you need to cast the "chicken" variable to EuropeanHen class type. The above is valid only for dynamic class objects. For static class objects, the type of the variable not only limits the number of available methods, but also specifies the implementation of these methods.
Lucas Hoage
Level 14 , Savannah, United States
12 June 2020, 21:13
A little tough. Doable.
Level 15 , Colnbrook, United Kingdom
2 May 2020, 21:53
getDescription ()
output must be exactly this format: <parent class>.getDescription() + " I come from <continent>. I lay <n> eggs a month." My output was a String.format(<parent class>.getDescription() + " I come from <continent>. I lay <n> eggs a month."....). Was giving me the right output, but wasn't passing the testing.
Andreas Dengler
Level 16 , Bielefeld, Deutschland
28 April 2020, 15:49
Hei I have another strange Problem. We need to create the classes if the hens in new files (I work on my phone) and it happens all the time. I create the file and change the class to what it needs to be go to the nect file change things there and when I look at the already finished file every change is gone and i need to redo it and when I am finished the other file is empty again. I will never be able to pass the task this way... I just realised that the files doesnt get deleted randomly every time you create a new file the changes of the other files get deleted
dabay wang Backend Developer at Amazon
5 April 2020, 22:31
Having an interface with only fields, like Continent, is not best practice. Maybe change to Enum instead.