Results 1 to 9 of 9
  1. #1
    e1007 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Smile read file and send them to different arraylist

    I have file with this specific format:

    Java Code:
    0  
    2 4   
    0 1 A  
    0 5 B  
    1 1 A  
    1 3 B  
    2 6 A  
    2 4 B  
    3 6 A  
    3 4 B  
    4 6 A  
    4 4 B  
    5 1 A  
    5 5 B  
    6 6 A  
    6 2 B
    * line 1 = start state
    * line 2 = accept state
    * line 3 - n = transition table
    * 1st column = state in
    * 2nd column = state out
    * A,B = symbol

    How can my FileReader in Java read these file into 5 different ArrayList
    (start state, final state, state in, state out and symbol)?

    i have my state class
    Java Code:
    public class State {
    
        String StateIn, StateOut, Symbol;
    
        public String getStateIn() {
            return StateIn;
        }
    
        public String getStateOut() {
            return StateOut;
        }
    
        public String getSymbol() {
            return Symbol;
        }
    
        public State(String StateIn, String StateOut, String Symbol) {
            this.StateIn = StateIn;
            this.StateOut = StateOut;
            this.Symbol = Symbol;
        }
    in my reader these arraylist will be arraylist<state>.
    Last edited by e1007; 12-23-2010 at 11:08 AM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    Why would you need five different ArrayLists for that? For example- what should be in your "start state" or "final state" ArrayLists? Why do you have a State class if you aren't going to use it?

    I think you should probably reread your instructions, because I think you're misunderstanding something pretty basic. I suppose I could be wrong, but your requirements don't seem to make any sense.

  3. #3
    e1007 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    ok..
    i think i made some basic mistake,.
    for these file, i need 5 basic information.
    start state -> to start a transition -> probably can remove it when i assign to 0 = start state
    final state -> list of accepted state
    state in, state out, n symbol -> to make a transition

    0 -> start state
    2 4 -> final state
    0 1 A -> stateIn, stateOut, symbol -> this the most important that i needed to separate to different array..
    to make it easier to read in file,. i make them to 1 class named state class
    Last edited by e1007; 12-23-2010 at 05:11 PM.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    Again, why do you have to separate them out into different arrays? You have a State class, which represents an entire row of your file. Use it. You should only need one collection (array or List, up to you) of State objects.

  5. #5
    e1007 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    these for string test method...

    user input another string and this program would return an output whether these string is accepted or not..

    i want to make a string tester in finite automata...

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    Quote Originally Posted by e1007 View Post
    these for string test method...

    user input another string and this program would return an output whether these string is accepted or not..

    i want to make a string tester in finite automata...
    Huh? Is this a separate question from your original post?

  7. #7
    e1007 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by KevinWorkman View Post
    Huh? Is this a separate question from your original post?

    no.
    my original post is still the same thing..

    let me explain a little bit more:
    i want to make a string tester in automata.

    1. i need to read these file into my program
    2. from these input file, i can make a string tester based on these file.

    and i can not make the filereader..
    how could i make the string tester??
    :(:(:(:(

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,037
    Rep Power
    10

    Default

    I'd suggest breaking your problem up into much smaller pieces. Even I am having trouble keeping all of your different requirements in my head.

    First, worry about inputting the information from the file. When you have that working independent of the rest of the program, then worry about the next step, which you'll also do independent of the rest of the program (including the file input).

    Create an SSCCE for each step, focusing on a specific, tiny question.

  9. #9
    e1007 is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    OK
    i'll try to break down the problem.

    i want to make a finite automata tool. which can accept a string test and transform to another automata.

    1. accepting a string test
    for accepting a string test, i need 5 element:
    -start state -> usually 1st state is the start state
    - final state -> this is the "decision maker" whether a string test is accepted or rejected by these automata. final state is >1. so i need an array to hold these data.
    -transition table -> table that show how these process begin.
    transition table contains: stateFrom, stateTo, and symbol.

    for example:
    0 -> start state
    2 4 -> final state
    0 1 A -> staterFrOM, stateTo, symbol

    thats why i need these file format like this:
    Java Code:
    0  
    2 4   
    0 1 A  
    0 5 B  
    1 1 A  
    1 3 B  
    2 6 A  
    2 4 B  
    3 6 A  
    3 4 B  
    4 6 A  
    4 4 B  
    5 1 A  
    5 5 B  
    6 6 A  
    6 2 B
    these file will check a string test from user :
    i.e: AAABBAAA

    and the program will make an output yes if accepted and no if rejected..

    in your opinion, what kind of data structure i should use in these problem?

Similar Threads

  1. How to read a string in a ArrayList?
    By warchieflll in forum New To Java
    Replies: 6
    Last Post: 12-09-2010, 06:58 PM
  2. Read txt file into arraylist
    By nickerhardt in forum New To Java
    Replies: 9
    Last Post: 08-04-2010, 05:34 PM
  3. Read txt file to arrayList
    By koddy in forum New To Java
    Replies: 14
    Last Post: 04-29-2010, 06:15 PM
  4. Replies: 2
    Last Post: 03-16-2010, 08:01 AM
  5. send/read int in a client/server app
    By dim_ath in forum New To Java
    Replies: 2
    Last Post: 01-03-2008, 02:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •