transfer form one state to another
<p>I use centralized patter to coding vending machine. The problem is I found out that I cannot change states. In the constructor, I initialized state to Ls[0], but when I go to the method public void coin() to change the state, I found that the state doesn't changed. The part of my code is:</p>

<pre><code> class Vending_machine {

    State st;
    private int price;
    private int k;
    private int k1;
    private int t;
    private int s;
    private State[] Ls;

    public Vending_machine() {
        Ls = new State[7];
        Ls[0] = new Idle();
        Ls[1] = new Coins_inserted();
        Ls[2] = new Sugar();
        Ls[3] = new No_small_cups();
        Ls[4] = new No_large_cups();
        Ls[5] = new Exit();
        Ls[6] = new Start();
        st = Ls[0];
        st.vm = this;

        k = 0;
        k1 = 0;
        t = 0;
        price = 0;
        s = 0;

    }

    public void setK(int k) {
        this.k = k;

    }

    public int getK() {
        return k;
    }

    public void setS(int s) {
        this.s = s;
    }

    public int getS() {
        return s;
    }......


          public void coin() {
        st.coin();
        if (st.getId() == 0) {
            if (t + 25 &lt; price) {
                // t=t+25;
                st = Ls[0];
            }
            if (t + 25 &gt;= price &amp;&amp; price &gt; 0) {
                // s=0;
                // t=0;
                st = Ls[1];
            }
        }......

 class State {

    public Vending_machine vm;
    int id = 0;
    public void coin() {}
        public void small_cup() {}
        public void large_cup() {}
        public void sugar() {}
        public void tea() {}
        public void insert_large_cups(int n) {}
        public void insert_small_cups(int n) {}
        public void set_price(int p) {}
    .......
}
   class Idle extends State {
    public void coin() {
        if (vm.getT() + 25 &lt; vm.getPrice()) {
            vm.setT((vm.getT()) + 25);
            System.out.println(vm.getT());
        }
        else if ((vm.getT() + 25 &gt;= vm.getPrice()) &amp;&amp; (vm.getPrice() &gt; 0)) {
            vm.setS(0);
            vm.setT(0);
        }
    }......
</code></pre>
