この問題をオブジェクト指向の方法で解決します。
新しいロボットまたは null を返す可能性のある public メソッド workForAMonth() を持つクラス Robot を作成します。
メインループは次のようになります (疑似コード):
create an empty List of robots
add one robot to it
while the list of robots has less than 200 entries
create a new list of the newly build robots
iterate the list of existing robots. for each robot:
call the workForAMonth method. When it returns a robot, append it to the list of newly build robots
append the newly build robots to the main list
add 1 to month
output month
workForAMonth メソッドは次のようになります。
increment the private month counter of this robot by 1
whe the counter is 5, set it back to 0
when the counter is 2 or larger, return a new Robot, else return null