Searching Arrays
Hi
Ive just created a programme that models a file system. I used arrays instead of linked lists etc.
The problem im having is i would like the end user to be able to search (ie company ID) and get the entire company details returned however im unable to think of the method to do this.
Can anyone help?
Thanks
[341 byte] By [
Komey999a] at [2007-10-2 5:30:17]

Here is the code ive written, it抯 a prototype of the final project. My aim is to let the end user search via flight no and it returns the destination.
import java.io.*;
import java.util.*;
public class ReadFromAirlineFile
{
// sequential text file input of characters
static BufferedReader fileInput;
public static void main(String args[]) throws IOException
{
String inputString;
String flight,dest;
int index = 0;
StringTokenizer tokens;
// 20 flights Indicated
Airline [] airlineArray = new Airline[20];
fileInput = new BufferedReader( new FileReader("flight_info.txt"));
inputString = fileInput.readLine();
// read the file until null is returned
while(inputString != null)
{
// First you need to split the string using the String Tokenizer
tokens = new StringTokenizer(inputString);
flight = tokens.nextToken(); // I have extracted the first component
// dest = Integer.parseInt(tokens.nextToken());// I have extracted the second component
dest = tokens.nextToken();
airlineArray[index] = new Airline(flight, dest);
index++;
inputString = fileInput.readLine();
} // end of while
// close the file
fileInput.close();
System.out.println("File read and closed");
// invoid mehtod to print the objects
printAirlineArray(airlineArray);
} // end of main
// Prints the array
public static void printAirlineArray(Airline [] airlineArrayIn)
{
for(int index = 0; index < airlineArrayIn.length; index++)
System.out.println(airlineArrayIn[index].getFlight() + " " + airlineArrayIn[index].getDest());
}
} // end of class ReadFromAirlineAsciiFile
> Here is the code ive written, it抯 a prototype of the
> final project. My aim is to let the end user search
> via flight no and it returns the destination.
> (irrelevant code snipped)
And so far you're doing absolutely nothing to fulfill any part of the search logic. Are you just sitting there waiting for someone to finish your code for you?
You were given advice earlier about using a Map (key-value pair). Sounds like the right track. The "key" to the map could be the flight number. The "value" to the map could be the Airline object.