public class BookSearchView extends FrameView {
ArrayList <String> books = new ArrayList <String>();
String bookList[] = null;
int bookNum[] = null;
String fileName = "/home/opnet/BookList.txt";
[cut a bunch of code]
private void getBooks(ArrayList <String> arrayList, int numArray[], String strArray[], String file)
{
BufferedReader readIn = null;
try {
readIn = new BufferedReader(new FileReader(file));
// loop until all lines have been read in
while(readIn.ready())
arrayList.add(readIn.readLine());
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
readIn.close();
} catch(IOException e) {
e.printStackTrace();
}
}
numArray = new int[arrayList.size()/2];
strArray = new String[arrayList.size()/2];
if(numArray == null)
System.out.println("array is emtpy");
// loop through the entire arraylist seperating
// all the strings and integers into different
// arrays.
for(int i = 0; i < books.size(); i++)
{
int count1 = 0;
int count2 = 0;
if(i%2 == 0)
{
numArray[count1] = Integer.parseInt(arrayList.get(i));
count1++;
}
else
{
strArray[count2] = arrayList.get(i);
count2++;
}
}
}
private void findTitleButtonActionPerformed(java.awt.event.ActionEvent evt) {
int ID = 0;
String bookName = "";
if(books.isEmpty())
getBooks(books, bookNum, bookList, fileName);
if(bookNum == null)
System.out.println("ARRAY IS NULL!");
ID = Integer.parseInt(inputField.getText());
for(int i = 0; i < bookNum.length; i++)
{
if(ID == bookNum[i])
bookName = bookList[i];
else
bookName = "REFERENCE NUMBER NOT FOUND!";
}
outputLinear.setText(bookName);
if(binarySearch(bookNum, ID))
bookName = bookList[ID];
else
bookName = "REFERENCE NUMBER NOT FOUND!";
outputBinary.setText(bookName);
}
}