Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create objects from a text file?
    primarykey
    data
    text
    <p>I have a text file of information that I want to make into Objects.</p> <p>The text file looks like this: </p> <pre><code>mediterraneanAvenue 60 0 50 {2, 10, 30, 90, 250} 0 balticAvenue 60 0 50 {4, 20, 60, 180, 450} 0 </code></pre> <p>and so on. I have control over the text file so I can change it in any way I need. However, there are over 30 properties (yes, I am making Monopoly), and I am looking for a more efficient way to copy over the data.</p> <p>What I hope to achieve is mirror lines like this: </p> <p><code>Property mediterraneanAvenue = new Property (60, 0, 50, new int[]{2, 10, 30, 90, 250}, 0);</code></p> <p>I am having a problem with how to read this information from a text file. I've done some research both from my course resources, and the internet; it has been difficult finding solutions and those that I found were more complicated and inefficient than simply making the Objects myself</p> <p>What I have tried is:</p> <pre><code>Property[] properties = new Property[28]; </code></pre> <p>...</p> <pre><code>try { BufferedReader br = new BufferedReader (new FileReader ("property card info")); int i; String lineContents; while ((lineContents=br.readLine())!= null){ String[] parts = lineContents.split(" "); properties[i] = new Property (Integer.parseInt(parts[0]), parts[1], parts[2], parts [3], parts[4], parts[5]); i++; } } catch (IOException e){ // TODO Auto-generated catch block e.printStackTrace(); } </code></pre> <p>I parsed every part of the deceleration, but when I copied over the code I deleted all but the first to keep the line short. I seem to be moving in the right direction, but I'm getting an undefined constructor error, and can't figure out how to make the section that is an array into an int[]</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.
 

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