Note that there are some explanatory texts on larger screens.

plurals
  1. POReading line from a file, and manipulating individual words from each line?
    primarykey
    data
    text
    <p>I am attempting to the read-in a .txt file and create a map to calculate total property listed in dollars and cents for each agent id. The agent ids are the three digit numbers at the end of each line. The problem is, I'm not exactly sure how to go about doing this. <br/></p> <p>I'm thinking I should create a while loop and add each line to an arraylist, and then..... I'm lost.</p> <p><code> 110001 commercial 500000.00 101<br> 110223 residential 100000.00 101<br> 110333 land 30000.00 105<br> 110442 farm 200000.00 106<br> 110421 land 40000.00 107<br> 112352 residential 250000.00 110 </code></p> <p>Ok, I know It has been a long time since I started this thread, but I haven't been able to revisit this problem for weeks now. (I'm attempting to learn this for personal growth, so it hasn't been priority) So far I have come this far...</p> <p>My method for creating the map is this:</p> <pre><code>public void createMap() { if(in != null) { while(in.hasNextLine()) { String s = in.nextLine().trim(); System.out.print(s); String[] p = s.split(" "); String agentId = p[3]; double property = Double.valueOf(p[2]); if(!map.containsKey(agentId)){ //if not then add the new key with new value map.put(agentId, property); in.nextLine(); } else { //if key is present, add the value.. map.put(agentId, map.get(agentId) + property); in.nextLine(); } } } } </code></pre> <p>Then in my program that I am running: I convert map to a Set and using a enhanced for-loop print each key and value.</p> <pre><code>Set&lt;String&gt; keySet = examp.map.keySet(); for (String key : keySet) { double value = examp.map.get(key); System.out.println(key + "-&gt;" + value); } </code></pre> <p>my output however gives me this: {} "empty brackets"! What am I doing wrong?</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.
 

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