This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Data structure help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Data structure help" Watch "Data structure help" New topic

Data structure help

Sam Battery

Joined: Oct 05, 2000
Posts: 10
I'm working on an applet that draws information from a text file for display in text fields for calculation. The trouble I'm having is this:
The numbers are broken down by state.
Then each state has 3 columns of figures (all of the same data type) broken down by type. There are 4 rows in each column.
I don't know how to draw the data from the file into the applet and how to store it once it has been added. I figure I would use a stream to input the data but how do I tell the stream which state to draw from and which column within the state to display. What sort of data structure (array, Vector, hashtable) would I use and how do I write my file objects to it? I'm new to Java and this is the most complicated thing I've had to do. Any help would be most appreciated. Thank you in advance.
Marius Holm
Ranch Hand

Joined: Sep 11, 2000
Posts: 84
I think you should provide more info so that people understand your problem better. It could be my english, but I didn't get your point with states and what the numbers were for. (United States or program states? )
[This message has been edited by Marius Holm (edited January 22, 2001).]
Sam Battery

Joined: Oct 05, 2000
Posts: 10
I'm sure your English is fine. I was referring to U.S. states. The data I'm working with is the alcohol tax rate for individual U.S. states. The user will select his state from a Choice list, then three columns of TextFields will populate with the tax data for liquor, beer, and wine. Consumption rates for each type of alcohol will also be included. The data can be organized in a text file any way I see fit, but I don't know how to go about retrieving the right data and storing it for access by the applet.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Here is the way I would do it... I would have the text file on the server ( and either hardcode this into the applet or have it passed in as a parameter. (i.e. somehow it basically has to boil down to

Then, use this URL to open a InputStream :

Then create a StreamTokenizer based off the InputStream :

Hope you could understand the code above... Basically, a StreamTokenizer doesn't take an InputStream directly, but it will take a BufferedReader, which takes a InputStreamReader, which takes an InputStream (finally! ).
Then just process your records... you will need to look at documentation on StreamTokenizer ( ) and look at your data to see how to do this, and you can store this data in your program any way you wish (i.e. arrays, Collections, or new class...). Basically to read a token from input you call st.nextToken(), and assign it to variables with st.sval for Strings, st.nval for doubles (which can then be cast to other types).

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sam Battery

Joined: Oct 05, 2000
Posts: 10
Thanks I've never heard of that. How would I do it with a file object instead of a URL? What sort of exceptions does this thing throw?
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I've an Applet live online with the source code, which used the technique Nathan Pruett described, and it can used as an application too. You can see the comparison of them.
Take a look:
Be a little patient to wait for some image downloads.
subject: Data structure help
Similar Threads
IBM Exam 157 - Questions and Answers (Sample Exam)
Passing more than one object
How to store whole XML in a table of a database
Is this a job for the controller or the model?
passed SCJD with 360/400