wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes if statement (using BlueJ) and equalsIgnoreCase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if statement (using BlueJ) and equalsIgnoreCase" Watch "if statement (using BlueJ) and equalsIgnoreCase" New topic
Author

if statement (using BlueJ) and equalsIgnoreCase

kel dobson
Greenhorn

Joined: Dec 20, 2003
Posts: 5
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?
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
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 ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
kel dobson
Greenhorn

Joined: Dec 20, 2003
Posts: 5
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 ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if statement (using BlueJ) and equalsIgnoreCase