Okay...I fixed it so that it displayes all of the user names at the end now, but I only want it to display the last entry...any ideas....
I am trying to fix an IndexOutOfBoundsException, I am not sure what I need to do. Please look and advise. Thanks
import java.io.*;
import java.util.ArrayList;
public class UserList
{
public static void main(String[] args) throws IOException
{
//declare variables
String str1, str2 = "username";
int index;
int initialCapacity = 5;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
ArrayList users = new ArrayList();
//get user input
System.out.print("Enter a user name: ");
str1 = dataIn.readLine();
//compare user input
while(str1.length() > 0)
{
//check for "username"
if(str1 == str2)
System.out.println("That user name is NOT allowed!");
else
{
//check for capacity of 5
if(users.size() == initialCapacity)
{
System.out.println("List is full!");
//okay I got it to work but not able to list the last user just all of them
System.out.println("Last entry is " +users);
}
else//check if user is in list already
if(!users.contains(str1))
{
users.add(str1);
System.out.println("User \""+str1+"\" added to user list.");
}
else//
System.out.println("User \""+str1+"\" already in user list.");
}
System.out.print("\nEnter a user name: ");
str1 = dataIn.readLine();
}
//completion of program
System.out.println("Program complete.");
}
}
This post has been edited by JamesAngie: 25 March 2008 - 11:01 AM

New Topic/Question
Reply




MultiQuote






|