Question: I need help with the accepts method. The method takes in a string of 1's and 0's and test to see if its acceeted by

I need help with the accepts method. The method takes in a string of 1's and 0's and test to see if its acceeted by the langauge. I also need help with the twoString printing the delta

import java.util.HashMap;

import java.util.LinkedHashSet;

import java.util.Set;

public class DFA implements DFAInterface, FAInterface{

private Set states;

private Set finalstate;

private HashMap mapState;

private DFAState startState;

private Set alphabet;

public DFA(){

states = new LinkedHashSet<>();

finalstate = new LinkedHashSet<>();

alphabet = new LinkedHashSet<>();

}

@Override

public boolean accepts(String s) {

return false;

}

@Override

public DFAState getToState(DFAState from, char onSymb) {

return from.getState(onSymb);

}

/**

* Adds the initial state to the DFA instance

* @param name is the label of the start state

*/

@Override

public void addStartState(String name) {

startState = new DFAState(name);

startState.getName();

states.add(startState);

}

@Override

public void addState(String name) {

DFAState state = new DFAState(name);

states.add(state);

}

@Override

public void addFinalState(String name) {

DFAState fin = new DFAState(name);

finalstate.add(fin);

states.add(fin);

}

public DFAState getStates(String Name){

for (DFAState s: states){

if (s.getName() == Name){

return s;

}

}

DFAState s = new DFAState(Name);

return s;

}

@Override

public void addTransition(String fromState, char onSymb, String toState) {

DFAState from = getStates(fromState);

DFAState to = getStates(toState);

from.addTrans(onSymb,to);

alphabet.add(onSymb);

}

@Override

public Set getStates() {

return states;

}

@Override

public Set getFinalStates() {

return finalstate;

}

@Override

public State getStartState() {

return startState;

}

@Override

/**

* Getter for Sigma

* @return the alphabet of FA

*/

public Set getABC() {

return alphabet;

}

/**

* Construct the textual representation of the DFA, for example

* A simple two state DFA

* Q = { a b }

* Sigma = { 0 1 }

* delta =

* 0 1

* a a b

* b a b

* q0 = a

* F = { b }

*

* The order of the states and the alphabet is the order

* in which they were instantiated in the DFA.

*

* @return String representation of the DFA

*/

public String toString() {

Set fin = getFinalStates();

Set alph = getABC();

State intial = getStartState();

StringBuilder build = new StringBuilder();

String newLine = System.getProperty("line.separator");

build.append("Q = { ");

for (DFAState p : states) {

build.append(p.getName() + " ");

}

build.append("}");

//print string alphabet

build.append(newLine + "Sigma = { ");

for (Character s : alph ) {

build.append(s.toString() + " ");

}

build.append("}" );

build.append(newLine + "delta = " + newLine);

for (DFAState s : states) {

// build.append(allstates + newLine);

}

//print start state

build.append("q0 = { ");

build.append(intial.getName().toString() + " }" + newLine);

// build.append(intial.() + " }" + newLine);

build.append("F = { ");

for (DFAState f : finalstate ) {

build.append(f + " ");

}

build.append("}");

return build.toString();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!