I have trouble in BlueJ with anything other then a very simple test to an 'if' statement. Can I compare a new input string with equalsIgnoreCase with a name recovered from an ArrayList object by using toString() and passing the 'name' variable back to the constructor of the first class to prevent two similar names being input?
Can you write down your program ? 1. "compare a new input string with equalsIgnoreCase with a name" YES 2. "recovered from an ArrayList object by using toString()" ??? arrayList.toString() -- WRONG String name = (String)arrayList.get(i) -- OK 3. "and passing the 'name' variable back to the constructor" ??? 4. "of the first class to prevent two similar names being input?" ???
My version: ArrayList list = new ArrayList(); for(; String str = inputString(); String normalizedStr = str.toLowerCase(); if( list.contains(normalizedStr) ) System.out.println("Already exists"); else list.add(normalizedStr); } inputString() - function that ask user to input string somehow... [ December 22, 2003: Message edited by: Igor Ko ]
I dunno how you did that Igor Kel, please attempt coding it yourself and posting the code here. We'll be pleased to help once we can understand what you are trying to do. Use the "code" button below the edit box so you can make the code keep its formatted layout.
Hi Guys Problem is a java program in BlueJ, which needs to store names and ages in an arraylist for members of a "computer games club" for my college project. A second arraylist holds a list of computer games I want to stop members "enrolling" using the same name - eg 'Fred and Fred = no' 'Fred and Freda = ok' Classes: Member and Club. Member holds instances of members and Club is an arraylist for members With help from others at JavaRanch I have got this side of the project running. Part of my problem (apart from being stupid!) is getting communication between two different object / classes, and to some extent this seems compounded by BlueJ which doesn't always do what I think it should ?? I was trying to use similar syntax to a system.out.println call to return the 'anme' field from objects in the arraylist to compare with each new object in the constructor of Member. I have been trying a method call to Club which I have called 'public void nameFromArrayList()' but the code is getting messy and I have commented out some lines I have tried just to keep it compiling and running. Anyway apologies for my code - it seems over long compared with the examples I read on these forum pages. tia kel
[ December 23, 2003: Message edited by: kel dobson ]
kel, What's your question, exactly? If it's still what you inquired about at the top of this thread, then sure you might be able to do something like that, and Igor has already posted one partial solution. There might be a simpler/easier-to-understand way to accomplish such a task.