• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a Phony Address Book  RSS feed

 
Jeff Sak
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a phony address book that randomly generates 1000 {firstName, lastName, streetName, state, zipCode, phoneNumber} in that order. I have a list of common first names and last names, and a list of common street names. I would like to read in the file and pull in the data from there, but I have problems figuring out how to randomly generate a name from a list(instead of just outputting each name in order). Currently, I am just using an arrayList and storing data that I input myself, but I am having trouble outputting randomly generated streetNames and States with it. I am using java.util.Collections to randomize the arrayList, but I am getting an error when I try to run the code and don't understand why. I will post some sample code below for you to see. Any help for how I can organize this and out put my data is very much appreciated.

Just for this sample code the goal is to get it to out put something like {Second, CA} and then {Third, OR} or something that is randomly generated. But I only want one from each arrayList.

 
Norman Radder
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting an error

Please copy the full text of the error message and paste it here if you want help solving the problem.
 
Jeff Sak
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this error, Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>, when I try and run the code.

 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your program didn't compile.

Missing final closing brace.
state(i) should be state.get(i)

The compiler error message should have given you more information so that you could make this determination yourself.
 
Jeff Sak
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I feel like a fool for not noticing that before. So now I am wondering, before I start adding about 50 names and addresses to this arrayList, is there an easier way to read a file and add the information into an arrayList? I put sample code of a previous program I wrote that took out .htm code and converting it to a .txt file. Is there a way for me to make a similar loop but instead add each line into a certain arrayList? I feel this would be a more efficient way of doing this. If not I will continue to add sample data manually into the arrayList.

 
Jeff Sak
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I start testing out the code, with added data, I realize that the loop I wrote wont compile through because one arrayList has more in the list than the other. How can I make it so that I can use repeated data from the same list if one list is smaller than the other?
 
Jeff Sak
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Sak wrote:As I start testing out the code, with added data, I realize that the loop I wrote wont compile through because one arrayList has more in the list than the other. How can I make it so that I can use repeated data from the same list if one list is smaller than the other? I will have multiple arrayLists and all will be different sizes.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of shuffle(), why not just get a random list item?
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a copy of Head First Java by Sierra and Bates, that sounds rather like the PhraseOMatic app.
The uncompilable exception is something which occurs on IDEs; it will have been preceded by a popup window inviting you to correct the error before proceeding, and the error will be marked with a red mark against the offending line of code. Look at our FAQ about it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!