Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Copy Constructor not going as planned
    primarykey
    data
    text
    <p>I have a bit of a problem. I'm making a Finite Automata checker. Given an input, and the DFA, does it end on a accepting state.</p> <p>My problem is creating a new DFA_State from another's target.</p> <pre><code>DFA_State state0, state1, curr_state, init_state, temp; //fine, I think state0 = new DFA_State(); state1 = new DFA_State(); state0 = new DFA_State("State 0",true, state0, state1); //fine, I think init_state = new DFA_State(state0); //fine, I think </code></pre> <p>but, this bit is throwing up problems.</p> <pre><code>temp = new DFA_State(curr_state.nextState(arr1[i])); * * curr_state = new DFA_State(temp); </code></pre> <p>Thanks for any help, Dave</p> <p>Edit: God I was retarded when I did this, AFAIK, I just wasn't thinking straight, added methods to set the values to the DFA_State object.</p> <pre><code>//in DFA_State class public void set(DFA_State on_0, DFA_State on_1, Boolean is_accepting, String name){ this.on_0 = on_0; this.on_1 = on_1; this.is_accepting = is_accepting; this.name = name; } //in main DFA_State state0, state1, curr_state; state0 = new DFA_State(); state1 = new DFA_State(); state0.set(state0, state1, false, "State 0"); state1.set(state1, state0, true, "State 1"); curr_state = state0;//initial state //iterate across string input changing curr_state depending on char c curr_state = getNextState(c); //at end if(curr_state.isAccepting()) System.out.println("Valid, " + curr_state.getName() + " is accepting); else System.out.println("Invalid, " + curr_state.getName() + " is not accepting); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload