Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:42:42+00:00 2026-05-26T10:42:42+00:00

I have a bit of a problem. I’m making a Finite Automata checker. Given

  • 0

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.

My problem is creating a new DFA_State from another’s target.

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

but, this bit is throwing up problems.

temp = new DFA_State(curr_state.nextState(arr1[i]));
*
*
curr_state = new DFA_State(temp);

Thanks for any help,
Dave

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.

//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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:42:42+00:00Added an answer on May 26, 2026 at 10:42 am

    In that first line, you declare the variables state0, state1, curr_state, init_state and temp as being variables of type DFA_State. However, that only declares them, they are not yet initialized. The next few lines are all okay. Second line creates a state without anything in it and assigns it to state0, so does the third line for state1. Fourth line overwrites your previous state0 assignment with a new DFA_State that has actual contents. Fifth line creates a DFA_State as a copy of state0 and assigns it to init_state.

    Assuming there’s nothing in between this and the first line of your second code block, now you’ll get a problem. You’re assigning temp with a new DFA_State that uses a copy-constructor with an argument relying on curr_state. But at that point, that variable hasn’t been initialized yet. Just because it was declared doesn’t mean it has somehow already been structured in memory. When you call nextState on it, there’s simply no variable to resolve this to. Don’t expect to get something like a pointer that will eventually point to a part of what you put in curr_state.

    I’m just guessing, but from your code style I’d say you have a background in C or C++. Look into the differences between those languages and Java. If possible, I’d also advise you to make your DFA_State class immutable, since this is more reliable and will avoid mistakes. That means getting rid of the no-args constructor. Here’s a reworking of it (not actually compiled, might contain errors):

    package foundations.of.computing;
    
    /**
     *
     * @author Kayotic
     */
    class DFA_State {
        private final String state;
        private final DFA_State on_0;
        private final DFA_State on_1;
        private final boolean isAccepting;
        //private DFA_State dummy;
    
        public DFA_State(DFA_State arg) {
            //this(arg.is_accepting(), arg.on0(), arg.on1());
            state = arg.get_name();
            isAccepting = arg.is_accepting();
            on_0 = arg.on0();
            on_1 = arg.on1();
        }
    
        public DFA_State(String name, Boolean accepting, DFA_State on0, DFA_State on1) {
            state = name;
            isAccepting = accepting;
            on_0 = on0;
            on_1 = on1;
        }
    
        public String get_name(){
            return state;
        }
    
    
        public Boolean is_accepting() {
            return isAccepting;
        }
    
        public DFA_State on0() {
            return on_0;
        }
    
        public DFA_State on1() {
            return on_1;
        }
    
        public DFA_State nextState(char i) {
            if (i == '0') {
                return on0();
            } else if (i == '1') {
                return on1();
            } else {
                System.out.println("Error with input");
                return null;
            }
        }
    }
    

    Even if you can’t make the instance variables final, it’s best to at least make them private, since you already have methods for getting them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a bit of problem figuring what Perl does in the following
As the title state, I have a bit problem with sql statement. I have
I have a bit of problem when trying to validate my page as HTML5.
I have a bit of a problem that I can't seem to code my
I have a bit of a problem. I am trying to do the following
I have a bit of a problem building my project. I'm getting the bellow
I have a bit of a problem here. I have a third party ActiveX
So, I have a bit of a problem. I'm trying to convert an array
I'm quite new to MediaWiki, and now I have a bit of a problem.
I have a bit of a strange problem. I have a music app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.