This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statement (using BlueJ) and equalsIgnoreCase

 
kel dobson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kel dobson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic