• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing file and displaying grouped content

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been working on this stupid code for days. I cannot figure out why I am not getting the correct output. The input file contains:

110001 commercial 500000.00 101
110223 residential 100000.00 101
110020 commercial 1000000.00 107
110333 land 30000.00 105
110442 farm 200000.00 106
110421 land 40000.00 107
112352 residential 250000.00 110

The output should be:



COMMERICAL
FARM
LAND
RESIDENTIAL

101 600000.00
105 30000.00
106 200000.00
107 1040000.00
110 250000.00

BUT all I get is:

COMMERCIAL
FARM
LAND
RESIDENTIAL

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Javaranch, Kiki Thomas.

When I execute your code I get the below output.



But you have mentioned that you see only the property types printed. Could you please verify it again?

The catch block in the code is blank without printing any necessary information on the Exception like below.

Never have a catch block as blank, else you would never know if the Exception ever occurred. At least print the Exception trace using getStackTrace() method.

Please UseAMeaningfulSubjectLine next time other than "Please HELP". I have fixed it this time for you.
 
Kiki Thomas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the post title. I have been very frustrated. I will correct that in the future.

I just re-ran the code and received the same output as previously posted (only titles.) I did add


to the IOException catch. To be clear, I am reading the information from a file called listings.txt then outputting to the agentReport.txt. Both the on screen display and output file both contain the same (lack of) information. I am writing and running this in Netbeans.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just put



in your catch-block. There's no need to do something more complicated which throws away potentially useful information.
 
Kiki Thomas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No errors print when outputting the file, just the incomplete information. I am still only getting:

COMMERCIAL
FARM
LAND
RESIDENTIAL

I have packaged and ran as a jar file in the cmd prompt to eliminate Netbeans.
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should take the following code fragment that exists in agentValue method



and put it outside the loop that reads the file (in our case, outside the "while (in.hasNextLine())"). As you can see, you are putting the keys and values correctly into your Map, but every time you read a new line, you add a new value to the tail Set (thus getting duplicate values). By putting it outside the loop, you put in the tail Set the correct values.

I hope this helped you a little bit.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kiki,

If you still haven't got the desired output, I advise you to post your modified code, contents of the input file again.
reply
    Bookmark Topic Watch Topic
  • New Topic