01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package state.three;

interface I {
  public int f();
  public int g();
  public void changeDirection();
}

class C implements I {
  private CState state = CState.MINUS;
  int i;
  int j;
  public int f() {
    return state.f(this);
  }
  public int g() {
    return state.g(this);
  }
  public void changeDirection() {
    state = (state==CState.MINUS) ? CState.PLUS : CState.MINUS;
  }
}