Results 1 to 2 of 2
Thread: Debugging Assignment
- 04-02-2012, 05:10 AM #1
Member
- Join Date
- Mar 2012
- Location
- Palestine Texas
- Posts
- 18
- Rep Power
- 0
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(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at UserList.main(UserList.java:37)
Java Code:import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; 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(System.in)); 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!"); else { if(users.size() == initialCapacity) { System.out.println("List is full!"); System.out.println("Last entry is "+users.get(initialCapacity)); } else 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(); } System.out.println("Program complete."); } }
- 04-02-2012, 07:08 AM #2
Similar Threads
-
debugging
By vanotd21 in forum New To JavaReplies: 4Last Post: 01-18-2012, 11:02 AM -
help debugging
By mluu510 in forum New To JavaReplies: 3Last Post: 08-21-2010, 01:28 PM -
Debugging Help Needed
By vittoire in forum New To JavaReplies: 3Last Post: 01-26-2010, 05:31 PM -
Debugging
By daro in forum EclipseReplies: 0Last Post: 07-22-2009, 05:02 PM -
Debugging with Eclipse 3.4.0
By edcaru in forum New To JavaReplies: 2Last Post: 11-07-2008, 06:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks