Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Tokenizing a line and searching

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to write and read from a 'database-like text file.
I'm simply trying to search through the text file for a certain value, the student ID.
Each line represents one student. The format looks like:

etc

I'm basically trying to find a student by their student ID.
My current attempt doesn't seem to work so well:



This current method is a result of me messing around with it and changing things at random.
My main problem is: it always returns the last student in the file, and I can't seem to figure it out.
I'm sure it has something to do with my logic. I'm pretty tired at the moment, so this is getting harder and harder by the hour, haha.

Anyone see the problem?
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I m not sure exactly what you search here ? If you found "studentID" , then break the loop.



there is no information that is stored in the loop except "count".
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scanner will be surely helpful. Use pattern matching to get the line with student id.
 
Ryan Akim
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, thanks for the reply.
That would work and it would be convenient; however, my professor pretty much forbids the use of break statements anywhere outside of switch() statements. :/

EDIT: I will look into Scanner and matching thanks for the reply.
 
permaculture is largely about replacing oil with people. And one tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic