Head-First-Design-Patterns icon indicating copy to clipboard operation
Head-First-Design-Patterns copied to clipboard

AlternatingDinerMenuIterator uses Calendar.DAY_OF_WEEK incorrectly

Open prashantpiyush1111 opened this issue 3 months ago • 0 comments

The constructor uses Calendar.DAY_OF_WEEK as if it represents the current day:

position = Calendar.DAY_OF_WEEK % 2;

However, Calendar.DAY_OF_WEEK is a field identifier constant, not the actual current day-of-week value. Therefore, this expression always produces the same starting position.

As a result, the iterator does not change its starting position based on the current day as intended.

Please retrieve the actual day-of-week value:

position = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) % 2;

This will make the iterator's starting position depend on the actual current day.

prashantpiyush1111 avatar Aug 26 '26 18:08 prashantpiyush1111