Hello. I need help writing a program that reads in a series of first names and stores them in a LinkedList. Do not store duplicate names. Allow the user to search for a first name.
This is what i have so far. Thank you.
import java.io.*;
import java.util.ListIterator;
import java.util.LinkedList;
public class llist
{
public static void main(String[] args)throws IOException
{
BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.i
n));
//create LinkedList object
LinkedList lList = new LinkedList();
String names="";
String response="";
System.out.print("");
System.out.print("Input a name:");
names = dataIn.readLine();
System.out.print("Would you like to enter another name? Enter yes or press any key to exit.");
response = dataIn.readLine();
if (response != null)
{
response = response.toUpperCase();
}
while (response != null && response.equals("YES"))
{
//add elements to LinkedList
lList.add(names);
System.out.print("Input name:");
names = dataIn.readLine();
System.out.print("Would you like to enter another name? Enter yes or press any key to exit.");
response = dataIn.readLine();
if (response != null)
{
response = response.toUpperCase();
}
}
lList.add(names);
ListIterator itr = lList.listIterator();
System.out.println("");
System.out.println("This is the list of names entered:");
while(itr.hasNext())
{
System.out.println(itr.nex
t());
}
System.out.println("");
}
}