Kotlinlearncs.online LogoJava
Return to List

Solve: Even Odd Flip

Created By: Geoffrey Challen
/ Version: 2024.7.0

Create a public class EvenOddFlip. It should provide a single constructor accepting an int, which sets the initial state of the instance.

Provide two instance methods.

  1. setValue accepts a single int and updates the stored value. You should assert that the value passed to setValue is even if the current value is odd, and odd if the current value is even.
  2. isEven retrieves whether the current saved value is even.

Here's an example of how your class should work:

Related Lessons

Stuck? You may find these lessons helpful: