Create a fixed version of the Animal Test program.
We want to measure your knowledge of certain aspects of Java, and your ability to find, understand and solve the problems in the provided code.
There are lots of bugs in logic, design and algorithms, and you have to:
- Make the program run according to the specification below:
- Make the code run without crashing.
- You can change the code as much as you want, provided the result is correct.
- The specification has some ambiguities, so feel free to make assumptions where applicable (notice as a result there must be more than one valid solution).
- We value a simple elegant solution with solid code principles.
- You may use any version of the Java SE.
- Initially there is one wolf and ten sheep.
- One wolf:
- Eats one sheep per update.
- Always eats the last sheep to have been added.
- Each sheep:
- If the sheep has never had a partner.
- The sheep will attempt to find a free partner.
- Then if the sheep has a living partner:
- The sheep gives birth to one lamb per update.
- Once the sheep has had three lambs, it dies.
- If the sheep has never had a partner.
- The system will be updated six times.
- The world state should be printed for each cycle, giving the number of living sheep, dead sheep and wolves.