beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Flop Flip Object

Geoffrey Challen // 2021.2.0

Define a public class named Flop with a single public instance method named flip that takes no parameters and returns a Boolean. Flop should also provide a single public constructor that accepts a Boolean argument and sets the initial state of the Flop instance.

Flop maintains one piece of private state: the boolean. Calling flip changes the boolean from true to false or false to true and returns the old (not the new) state of the boolean. So, for example:

Note that the internal state should be private.