• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help With Passing A Method And Searching An Array  RSS feed

 
Corey Hartman
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working on this for 7 hours straight so my brain is fried... so forgive me if the answer is obvious...

I have no idea how to pass the methods listed below.



public ArrayList<Person> findPerson(String searchFor)


^ this method is suppose to search an array and find whatever you search (numerical or alphabetical)



i have this

I am not sure what i did wrong or how to fix it. Any hints or assistance would be great. I am not sure if how i am searching the method is correct or how to pass that to another class to put it inside of a switch statement.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey, you seem to be putting a lot of effort into learning Java in a very short time, but I get the feeling it's not working out for you.

Step away from these problems/assignments/tests or whatever they are, get yourself a good book on Java for beginners, and stop thinking about any particular problem. Your difficulties all seem to arise from not knowing the basics, and those are the same for every single piece of Java code you'll ever write.

Seriously, get up, walk away from your computer, go to the bookstore, and buy "Head First Java," or any of the other good books on Java for newcomers. I'm telling you, if you don't do this, you're going to drive yourself mad and, even if you get your programs to run, you're going to hate Java for the rest of your life, instead of learning a powerful and exciting new skill.

Now go get a book, and good luck.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't pass methods. You can search arrays. At this stage you need to remove all silicon from your life. Get the newspaper and some coffee/beer whatever, and turn the computer off. Forget about all programming until tomorrow.

Then write down on paper how you would go through an array looking for a particular element. And if you find it, how you would add it to a List. But first work out why you would want a List saying ["Corey","Corey","Corey","Corey"…etc…]
 
Brian Schuetz
Greenhorn
Posts: 25
Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is the program doing wrong or not doing right? Looking at the code I'd suggest carefully looking at your two last "if" statements. One is nested under the other. I'm not sure that's what you intended. Also your "matches.add(p)" statement will always execute, giving you every element in the ArrayList.

I hope that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!