I would like to compare user input against and entire file and print out message when item is found or item not found. My program below appears to do that but it is doings so one line at a time. Please help.
Jems
import java.util.*;
import java.text.*;
import java.io.*;
import java.lang.*;
//------------------------------------------------------------------------//
// class ShareHolder //
// Provides information about a specific shareholder //
//------------------------------------------------------------------------//
public class ShareHolder implements Comparable
{
String firstName;
String lastName;
//------------------------------------------------------------------------//
// ShareHolder() //
// Default Constructor. Sets the first and last name to an empty string //
//------------------------------------------------------------------------//
public ShareHolder()
{
firstName = "";
lastName = "";
}
//------------------------------------------------------------------------//
// ShareHolder(String,String) //
// Constructor. Sets the shareholders first name and last name to the //
// specified values //
//------------------------------------------------------------------------//
public ShareHolder(String first, String last)
{
firstName = first;
lastName = last;
}
//------------------------------------------------------------------------//
// int CompareTo(Object) //
// Returns a negative number if this is less than other, zero if //
// this is equal to other, and a positive number if this is greater //
//------------------------------------------------------------------------//
public int compareTo(Object other)
{
String thisString = lastName+firstName;
String otherString = ((ShareHolder)(other)).lastName +
((ShareHolder)(other)).firstName;
return thisString.compareTo(otherString);
}
//------------------------------------------------------------------------//
// String getFirstName() //
// Returns the first name of the shareholder //
//------------------------------------------------------------------------//
public String getFirstName()
{
return firstName;
}
//------------------------------------------------------------------------//
// String getLastName() //
// Returns the last name of the shareholder //
//------------------------------------------------------------------------//
public String getLastName()
{
return lastName;
}
// This is the driver
public static void main (String[] args) throws IOException {
ArrayList<String> members = new ArrayList<String>();
BufferedReader br = null;
br = new BufferedReader( new FileReader( "owners.txt" ) );
String allNames = "";
while ((allNames = br.readLine()) != null)
members.add(allNames);
// Create an array
String[] names = new String[members.size()];
members.toArray(names);
// Takes user entry
Scanner user = new Scanner(System.in);
System.out.println("Please enter your first name:"); // Enter first
String first = user.next();
System.out.println("Please enter your last name:"); // Enter last
String last = user.next();
// Create new object
ShareHolder out = new ShareHolder(first,last);
System.out.println(out.getFirstName()+" "+out.getLastName());
String str = "";
str = out.getFirstName()+" "+out.getLastName();
for (int i = 0; i < names.length; i++)
if (str.equalsIgnoreCase(names[i])) {
System.out.println("You may participate in the meeting!");
}
else {
System.out.println("Sorry your name is not on the list!");
}
}
}