0

hi there!
I have a file.txt looks like this:

Michael
001
Yeeka
002
Sam
003
Tom
004

Michael is the member name, while 001 is the ID number.
How can I write a coding to validate that whether user has type in the correct name and ID that is inside the file.txt?
such as, I have a coding that ask user to enter name and ID.
if user type "Michael" and "001", how can I have a coding that can validate user is a member?
please help!
thanks a lot!

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by verruckt24
0

You can use an Object of the class Scanner to read in the names from the text file. Store them into an array. Then you can write a search method to search for a name based on what the user inputs. This method could be as simple as checking to see if the String that the user inputs is equal to any of the Strings in the array, using the equals method of the String class.

0

>Store them into an array
I would like to suggest just a better way. Use a Map instead it would also give you better search capabilities than an array. Instead of searching of all the strings in the array, a Map would offer you search functions.

Store the Id as the key and the name as the value in the Map.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.