Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Probably you are confused in how to use <code>Scanner</code> instance to read the file. In your <code>importFile</code> method, you have assumed that there are atleast 50 lines of data and reading it using <code>scanner.nextLine()</code>. You have to check whether there is a next line and then read it otherwise, it will throw <code>NoSuchElementException</code> when there is no next line. The code should be</p> <pre><code>while(scanner.hasNext()){ scanner.next(); } </code></pre> <p>or</p> <pre><code> while(scanner.hasNextLine()){ scanner.nextLine(); } </code></pre> <p>Similarly, in your <code>createFile</code> method are you sure that all your argument <code>String arrays</code> are of length <code>50</code>? <code>For</code> loop is always programmed to run for 50 times to create the <code>String</code> literal with assumed 50 index values (0-49) of all arrays passed to the method. This will cause <code>RuntimeException</code> when there is no index value found - <code>ArrayIndexOutOfBoundException</code>. You need to handle this by checking for all arrays <code>length</code> should be <code>50</code> before doing this operation. Preferrably, you should use <code>StringBuilder</code> instead of concatenating the<code>String instance inside a</code>loop<code>. In your</code>askState` method, you are not having a conditional loop to re-ask for the input, when the user keys in an invalid state. </p> <pre><code>while(invalidState(state)){ System.out.println("Please enter input"); state = keyboard.nextLine(); } </code></pre> <p>The other important thing is that you are invoking the <code>createFile</code> method for fifty times, which is not at all needed since you have all the various files data in array. Passing the arrays to <code>createFile</code> method once is enough and then write the logic to do the write operation of the total data into a single file</p> <pre><code>for (int x = 0; x &lt; NUM_STATES; x++) { createFile(stateNames, nicknames, capital, flowers, populations); </code></pre> <p>I would suggest that you have to debug your program completely to ensure that your code works in the same way you think. Hope this helps</p>
    singulars
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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