• Post Reply Bookmark Topic Watch Topic
  • New Topic

Search for next line in document looking for a name by user  RSS feed

 
Irving Luna
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need to create a program that reads from a txt files that has all the names used from 1900 to 2010 with the ranking for each respective decade. I have created my own methods to read from the file find the name and store the full line to be used in a different methods that will tokenize each int and put them in their respect decade, however im having trouble with my get name method, when i run it I get

java.util.Scanner[delimiters=\p{javaWhitespace}+][position=7][match valid=true][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]

can anyone explain this, and any suggestions for a better set up, im pretty sure I have the logic set up incorrect, in the method getName, im trying to create a while loop that scans the document until the last line, if the name is found, temp would equal the full line assigning it to the String getName and returning it to the method. If the name is not found, it would say "name not found" and request for another name, i was thinking about placing a while loop that would call onitself if name was not found, but I dont think that I can do this for this assignment.


 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anything which uses the keyword static that often is wrong, in my opinion. Not object‑oriented.
Delete that code. All of it. It looks as if you are guessing, and you have some dreadfully brittle code like a method which takes a Scanner (like Tommy Cooper saying, “Take a card, any card”) and expects to get an int from the user. You can guess 1000000 times and as long as your guesses are different from one another, chances are you will get one of them to work. Or you can think and plan and get something which works first time. Write down on paper what you intend to do and how you intend to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!