Array manipulation (adding, viewing, etc...)

How to check an array if a user input is there, then how to add to it.

Posted 03 December 2009 - 04:31 PM

I had to load up a .txt file into an array, and now I have to scan it for a name that the user is asked to input. Is this right so far? And how do I go about using a for loop to check if the user input is present?

Re: How to check an array if a user input is there, then how to add to it.

Posted 03 December 2009 - 04:42 PM

I guess I should have mentioned it in the original post but I have to do like I did. There are a few requirements for this program, I'll copy and paste all the hints given to us:

· The total number of records should be stored in a variable of type final int.

· Only one for loop is need to load the data from the file a2.txt into the Student
array. Make sure you read the total number of records before starting the execution of the
for loop.

· Once your data is loaded, use one main for loop to display the main menu and handle
the selection from the user. Inside this main for loop, use control structures based on the
user’s selection to determine the operations to be performed.

· In order to know if a record (i.e., full name) is in the database or not, use a for loop to
navigate from record to record and stop the loop once a matching record has been found.
HINT2: The body of this for loop should be empty.

· To navigate from course to course in a Student object, use the methods
getFirstCourse() and getNextCourse() in a for loop. For example:
for(String c = s.getFirstCourse(); c != null; c = s.getNextCourse())…

· See examples of executions on the next pages.

· All input are case sensitive (e.g., file names, full names in the database, and menu
selections). Assume the user is entering the correct inputs.

· Use the StringTokenizer() class to read the input file (comma delimited).