Results 1 to 4 of 4
  1. #1
    pecca-ve is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Default Search function with multiple hits and ability to chose what hit is correct?

    Hi. My first post here. :)

    I've made a program handling customers, orders, and products of a small buisness, using arraylists, as a schoolproject. My search function:

    public Order searchOrder(int orderNo){
    Order tmpOrder = null;
    int i = 0;
    boolean found = false;

    while (i < orderrow.size() && funnen == false){
    tmpOrder = orderrow.get(i);
    if (tmpOrder.getOrderNo() == orderNo) {
    found = true; }
    i++;
    }
    if (found == false) {
    tmpOrder = null;
    }
    return tmpOrder;
    }

    My problem is that an order can have several different "orderrows" containing different products but still be a part of the same order (same id). Is there a way I can search for all of them and display them (if more than one) in a pop-up window where I could chose which one I was looking for and import that one for possible edit.

    Thanks in advance. :)

  2. #2
    gundum584 is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    hmmh put all the orders with the same id in an array. Then search that array for the name of the item you wish to edit.
    not sure if this will work but you can give it a crack.

  3. #3
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    If I understand what you are asking....a) you could use and return another List containing the found elements or b) use a Map, keyed with ordernum and valued with the List containing the contents

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by pecca-ve View Post
    Hi. My first post here. :)

    I've made a program handling customers, orders, and products of a small buisness, using arraylists, as a schoolproject. My search function:

    public Order searchOrder(int orderNo){
    Order tmpOrder = null;
    int i = 0;
    boolean found = false;

    while (i < orderrow.size() && funnen == false){
    tmpOrder = orderrow.get(i);
    if (tmpOrder.getOrderNo() == orderNo) {
    found = true; }
    i++;
    }
    if (found == false) {
    tmpOrder = null;
    }
    return tmpOrder;
    }

    My problem is that an order can have several different "orderrows" containing different products but still be a part of the same order (same id). Is there a way I can search for all of them and display them (if more than one) in a pop-up window where I could chose which one I was looking for and import that one for possible edit.

    Thanks in advance. :)

    Yes. How you do this will depend on the structure of the Order class, something you've not told us a lot about. But also, is this a GUI program or a command line program? Regardless, you'll want to create a non-GUI selectOrderItem method and perhaps an enumerateOrderItems method which returns a List of items and then use these methods in your GUI or non-GUI program depending on the need.

    Also, please read the first link in my signature links below on how to use code tags. Your post without tags is very hard to read.

    Much luck!

Similar Threads

  1. Pass multiple object types to one function
    By desmo in forum New To Java
    Replies: 3
    Last Post: 10-08-2010, 07:51 AM
  2. Replies: 4
    Last Post: 07-23-2009, 09:45 PM
  3. Search function for ArrayList?
    By javanoobie in forum New To Java
    Replies: 11
    Last Post: 04-17-2009, 08:38 PM
  4. Code for adding search function in an application
    By Avdhut in forum Threads and Synchronization
    Replies: 5
    Last Post: 03-03-2009, 10:15 AM
  5. Replies: 5
    Last Post: 08-26-2008, 03:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •