Finish this class to search a certain file indata.txt has the following data for
ID: 3635025 • Letter: F
Question
Finish this class to search a certain file indata.txthas the following data format:
firstname lastname M 01/01/1901 1111
firstname lastname M 02/04/2010 2222
firstname lastname F 10/18/1805 3333
firstname lastname M 01/03/1703 4444
------------------------------------------------------------------------------------------
public class Company
{
private Employee[ ] data;
private int numOfEmployees;
private int capacity;
public Company ( )
{
capacity = 100;
numOfEmployees = 0;
data = new Employee [capacity];
}
public Company (int newCapacity)
{
numOfEmployees = 0;
capacity = newCapacity;
data = new Employee [capacity];
}
public String toString ( )
{
String outString = "";
for (int i = 0; i < numOfEmployees; i++)
outString += data[i];
return outString;
}
//single occurrence (at most one match)
//sequential search
public int search (String key)
{
int foundIndex = -1;
for (int i = 0; i < numOfEmployees; i++)
{
if (key.equals ( data[i].getId ( ))
{
foundIndex = i;
break;
}
}
return foundIndex;
}
public void buildData ( )
{
Scanner inFile = null;
boolean fileOK = true;
String filename = "indata.txt";
Scanner kbd = new Scanner (System.in);
String inString = "";
do
{
try
{
inFile = new Scanner (new File (filename));
}
catch (FileNotFoundException ex)
{
System.out.println ("file error");
fileOK = false;
System.out.println ("another file name? ");
filename = kbd.nextLine ( );
}
} while (!fileOK);
while (infile.hasNext ( ))
{
inString = inFile.nextLine ( );
}
}
}