Results 1 to 2 of 2
  1. #1
    Valerie1067 is offline Member
    Join Date
    Mar 2012
    Palestine Texas
    Rep Power

    Default Debugging Assignment

    Hi there, I have a debugging assignment where I found all the errors and it compiles, but some of the output isn't what it's suppose to be. Any assistance is VERY appreciated!!

    input sam and get the output User "sam" added to user list, same for bob, ellen, and sue. I am suppose to enter username as a user name, and an output is suppose to read "That user name is NOT ALLOWED!" I am suppose to enter bob again, and get the output "bob already in user list." and at the end when I go to enter bill I am suppose to get the output that says "List is full!" "Program Complete."

    username doesn't cause an error, and when the list is full I get the error: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 6, Size: 6
    at java.util.ArrayList.RangeCheck(
    at java.util.ArrayList.get(
    at UserList.main(

    Java Code:
    import java.util.*;
    public class UserList
      public static void main(String[] args) throws IOException
    	  String str1, str2 = "username";
    	  int index;
    	  int initialCapacity = 6;
    	  BufferedReader dataIn = new BufferedReader(new InputStreamReader(;
    	  ArrayList<String> users = new ArrayList<String>();
    	  System.out.print("Enter a user name: ");
    	  str1 = dataIn.readLine();
          while(str1.length() > 0)
    		  if(str1 == str2)
    		      System.out.println("That user name is NOT allowed!");
    			  if(users.size() == initialCapacity)
    			   	  System.out.println("List is full!");
    				  System.out.println("Last entry is "+users.get(initialCapacity));
    					  System.out.println("User \""+str1+"\" added to user list.");
    				      System.out.println("User \""+str1+"\" already in user list.");
    	      System.out.print("\nEnter a user name: ");
    	      str1 = dataIn.readLine();
    	  System.out.println("Program complete.");

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Debugging Assignment

    Java indexes are zero-based. The first item in your list is users.get(0). Now, what's the index of the last item?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. debugging
    By vanotd21 in forum New To Java
    Replies: 4
    Last Post: 01-18-2012, 11:02 AM
  2. help debugging
    By mluu510 in forum New To Java
    Replies: 3
    Last Post: 08-21-2010, 01:28 PM
  3. Debugging Help Needed
    By vittoire in forum New To Java
    Replies: 3
    Last Post: 01-26-2010, 05:31 PM
  4. Debugging
    By daro in forum Eclipse
    Replies: 0
    Last Post: 07-22-2009, 05:02 PM
  5. Debugging with Eclipse 3.4.0
    By edcaru in forum New To Java
    Replies: 2
    Last Post: 11-07-2008, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts