Eggs of the Week
Emma's hens have been busy. A new variable, eggs, says which hen laid how many eggs on each day of the week, again as a text from Emma's notebook. A hen is an animal that lays eggs, so she's a good candidate for a subclass of Animal: a class Hen with a count of eggs and a method that adds to it.
Finish the program with the line Eggs this week:, and below it, every hen with her eggs, in the same order as in the list above. Then print how many eggs the hens laid in total:
Pearl hen 1
Eggs this week:
Goldie: 4
Pearl: 3
In total: 7A hen that laid nothing this week is in the list too, with 0 eggs. And the register and the lines above it stay as they were.
A tip: remember what the lesson on objects said about metamethods: a subclass doesn't inherit them. Yet hens have to print and compare like any other animal.
That's the whole project, and the last checkpoint. Your program reads a text with patterns, turns it into objects of a class and a subclass, sorts them with a metamethod, and prints them in columns that line up even with accents. In the next lesson, on coroutines, you'll write functions that can pause and continue later. After it comes the final project, in which you'll put the whole course together.
Instructions
Print the eggs of each hen.
Below, print how many eggs the hens laid in total.
Start programming for free
3/3