Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpinningDiskDevice
- {
- private int lastInput;
- private int transitions;
- /**
- Constructs a spinning disk device.
- */
- public SpinningDiskDevice()
- {
- lastInput = 0;
- transitions = -1;
- }
- /**
- Processes a new input
- @param input 0 or 1
- */
- public void add(int input)
- {
- if(input != lastInput)
- {
- lastInput = input;
- transitions++;
- }
- }
- /**
- Gets the number of transitions observed since this
- device has been constructed.
- */
- public int getTransitions()
- {
- return transitions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment