It's not a secret anymore!
The moose likes Beginning Java and the fly likes code for an if statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "code for an if statement" Watch "code for an if statement" New topic

code for an if statement

Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
i have created a menu and i want to create a loop through the menu any time a new entry is made so that it scans to check if the entry is already in the menu, if this is true then i want it to remove the entry from where it is in the menu and place it at the top. can anybody please suggest some possible code for this
Stephen Boston
Ranch Hand

Joined: Jul 14, 2005
Posts: 165
What kind of menu? Can you supply some code to show us what you have?

Steve<br /> <br />No matter where you go, there you are.<br /> <br />"My evil self is at the door, and I have no power to stop it."
Kenneth Albertson
Ranch Hand

Joined: Sep 18, 2005
Posts: 59
Hi there, Chris. Still working on this problem? A number of people made helpful suggestions when you asked the same question a couple of days ago. If you still don't know where to start, perhaps you need to go right back to the beginning. Tell us what classes you think that you need, and then the two fundamental things that you need to know about each class:
  • What do they need to know, ie fields, and
  • What do they need to do, ie methods.
  • Central to this problem is the design of a data structure to hold the menu items. The previous discussion suggested an array or a list. I suggest that you use an array, it will be an easier approach for a beginner.

    I also suggest that you do the problem in two parts. Start by ignoring the requirement to avoid duplicate entries, because that is the hardest part. Get everything else working, and by then you should have enough understanding of what you are doing to tackle the removal of duplicate entries as well.

    BTW, a quick refresher of How To Ask Questions On Java Ranch might be useful as well.
    [ October 13, 2005: Message edited by: Kym Thompson ]
    Henry Wong

    Joined: Sep 28, 2004
    Posts: 20521

    Another issue is, if you don't understand the answers, ask for clarification. Don't just ignore the answers.


    Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
    I agree. Here's the link:
    subject: code for an if statement
    jQuery in Action, 3rd edition