Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You want some nested loops to read the file.</p> <p>That's a poor way to describe the file-format. "Section" describes a section of the file. You can say that each section defines a category, with the first line the name of the category, subequent lines pairs of questions and answers, and terminated by a blank line/ or EOF.</p> <p>In pseudocode, essentially you want:</p> <pre><code>List&lt;Category&gt; categories = new ArrayList(); while (in.hasNextLine()) { String catName = in.readLine(); if (catName.trim().length() == 0) continue; // skip extra blank lines between Sections. Category cat = new Category( catName); categories.add( cat); while (in.hasNextLine()) { String line = in.readLine(); if (line.trim().length() == 0) break; // end of Section. // parse a Question &amp; it's Answer. TriviaQuestion question = parseQuestion( line); cat.addQuestion( question); } } // done. return categories; </code></pre> <blockquote> <p>I am supposed to make an ArrayList that will have 6 indexes. One for each category, then in each of the indexes i should have groups of questions and answers that I will be able to utilize for comparison.</p> </blockquote> <p>That's a fairly confused way of talking about something that actually should be pretty simple. You could say "there will be 6 categories". But actually, it's not necessary to fix or predetermine the size of the ArrayList -- so why mumble about this at all?</p> <blockquote> <p>I guess essentially an array inside of an arraylist.</p> </blockquote> <p>Use an ArrayList (indirectly) inside of an ArrayList. Lists/ArrayLists are much better to build dynamically, because (unlike an array) they don't have to be pre-sized or grown.</p> <p>But note that the 'Questions' list, should be held inside of the Category obect.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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