• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hashset I think.  RSS feed

 
Keith Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Code is not showing all of the values that I have entered.

Text File Input
==============
113333 business 500000.00 201
114444 industrial 100000.00 201
115555 business 1000000.00 207
116666 land 30000.00 205
117777 farm 200000.00 206
118888 land 40000.00 207
119999 industrial 250000.00 210
==============
I am getting....
==============
BUSINESS
FARM
INDUSTRIAL
LAND

205: 30000.0
201: 100000.0
206: 200000.0
207: 40000.0
=============
I need to get it to add up the separate number items.
Using the short number as the key I.E. 207.
so the first row would be 207: 1040000.00
Full text of how I need my output
I am mostly concerned with why I am not getting all of the elements.
=============
BUSINESS
FARM
INDUSTRIAL
LAND

201: 600000.00
207: 1040000.00
205: 30000.00
206: 200000.00
210: 250000.00


 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Numbers do not magically add up by themselves. You have to check if the key is already in the map, get its value, and sum it to the value you've just read.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a similar example in the Java™ Tutorials. Look in one of the "Map" sections.
 
Keith Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your information about adding key values.
That is helpfull. I did know I would need to work on that part of my work.
--------
One part that doesn't seem to make sence is the fact that even with how it is now,
it isn't showing all of the key's.
I understand the fact that it isn't adding the individual keys, that is how hashmaps, treemaps, ect.. work.
So I did know I would need to work on that.
--------
The issue I see is that it isn't even showing all unique keys?
 
Keith Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apon further review, it is dropping the last key in the text file used for input?
I am looking for why.. now.
let me know what you think.. and thanks agien.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at line #32 in your posted code. You have a line of data in memory, and then you say "If there's another line after this one then do (some important work)."

So what happens there when the line of data in memory is the last one in the file?
 
Keith Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I have found where my issue is coming from.




I believe I need to change the first part if(Scanner2.hasNext()) I think this might be starting it off wrong.
Or setting up a situation that if there is no next.. it stops. thereby not inputting my last element.?
Any thoughts.
 
Keith Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just read your comment about line 32.
... I am looking at it now.

Thanks.
 
Keith Anderson
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your help.

I commented out the line in question (line 32).
and funny enough all is well.
I am jumping back and forth between my IDE and TextPad.
I think I did a bit too much cutting and pasting.
============================
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!