3 Replies - 475 Views - Last Post: 01 November 2012 - 07:42 PM Rate Topic: -----

#1 aboschert  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 01-November 12

Java text file delimiters question

Posted 01 November 2012 - 06:38 PM

I am having trouble with separating text files into elements that are necessary to run my code. I must read in a text file, print a question, the possible answers, and ask for an answer, and move on to the next question and so on. My question is: how do I determine how to separate questions, answers, possible answers ect in my code? I want to use the ? in the questions to help split the file into the correct arrays, but am not sure how specifically. Here is a sample quiz file I have written:

How many licks does it take to get to the tootsie roll center of a tootsie pop?
4(this is the correct answer)
one
two
three
four(as in the fourth answer)
2
14
5
What is your name?
3
Arthur, King of the Britons
Sir Lancelot the Brave
Sir Robin the Not-Quite-So-Brave-As-Sir Lancelot
0
14
6
Who's on first?
5
What
Why
Because
Who
I don't know
3
14
7
Which of the following is a terror of the fire swamp?
4
Lightning sand
Flame spurt
R.O.U.S.
All of the above
3
14
4
Who is the all-time greatest pilot?
6
Manfred von Richthofen
Chuck Yeager
Hiraku Sulu
Luke Skywalker
Kara Thrace
Charles Lindbergh
4
14
9

Here is my code:

import java.util.*;
import java.io.*;
public class JavaApplication8 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
       
        Scanner inScan = new Scanner(System.in);
        
        String file_name;
        System.out.print("What is the full file path name?\n>>");
        file_name = inScan.next();
        
        Scanner fScan = new Scanner(new File(file_name));
        ArrayList<String> Questions = new ArrayList();
        ArrayList<String> possibleAnwers = new ArrayList();
        int [] rightAnswer = new int[//number of questions];
        
       
        
        while (fScan.hasNextLine()) 
        {
            if(fScan.nextLine//contains a question mark)
                    {
                       //adds line to question arraylist
                       //adds next line to answer integer array
                       //adds next lines to possible answers until an int is found
                
                    }
            else if(fScan.nextLine//contains an int)
                    {
                       //adds to statistics
                              
                    }
            else 
    
            Questions.add(fScan.nextLine());
        }
        
        
        
    }



Do not worry if there aren't all the arrays necessary; I am only worried about how to search for a particular substring/type

Is This A Good Question/Topic? 0
  • +

Replies To: Java text file delimiters question

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Java text file delimiters question

Posted 01 November 2012 - 06:58 PM

View Postaboschert, on 01 November 2012 - 09:38 PM, said:

how do I determine how to separate questions, answers, possible answers ect in my code?

That is one of the first question that should be resolved when deciding of the architecture of the data file
Once this is solved, writing the program to read the data file is a piece of cake

P.S.
in the real world, nce the marketing folks have decided what they want, writing the actual code is a peanut :)
Was This Post Helpful? 0
  • +
  • -

#3 aboschert  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 01-November 12

Re: Java text file delimiters question

Posted 01 November 2012 - 07:05 PM

View Postpbl, on 01 November 2012 - 06:58 PM, said:

View Postaboschert, on 01 November 2012 - 09:38 PM, said:

how do I determine how to separate questions, answers, possible answers ect in my code?

That is one of the first question that should be resolved when deciding of the architecture of the data file
Once this is solved, writing the program to read the data file is a piece of cake

P.S.
in the real world, nce the marketing folks have decided what they want, writing the actual code is a peanut :)



I know the structure of how to do what I'm asking, I just do not know how exactly the code necessary for implementing it
Was This Post Helpful? -1
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Java text file delimiters question

Posted 01 November 2012 - 07:42 PM

So post the structure !!!

why should we waste our time trying to guess it ?

Quote

My question is: how do I determine how to separate questions, answers, possible answers ect in my code?

Would be a lot easier if we know the rules ..., don't you agree ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1