Results 1 to 4 of 4

Thread: Array list help

  1. #1
    caramelxxx is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Array list help

    I have to define a method addOrder which has a formal parameter of type Order. It increments the number of orders called in and adds the Order to the end of the orders waiting delivery. I have written this code but the bit in red font is not compiling. Thanks.

    public DeliveryLog(int dd, int mm, int yy)
    {
    //provide code here
    //4.2
    numberOfOrders = 0;
    logDate = new Date(dd,mm,yy);
    ArrayList waitingList = new ArrayList();
    ArrayList deliveredList = new ArrayList();
    }

    private ArrayList<Order> waitingList;
    waitingList = new ArrayList <Order> ();
    public void addOrder (Order x)

    {
    waitingList.add(x);
    numberOfOrders = numberOfOrders ++;
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Array list help

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Array list help

    When seeking help with an error, post the entire error message.

    All executable code in a Java class must be inside the body of a method, constructor or initialization block. Only declarations (and declarations with initialization) are allowed out in the body of the class.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    256
    Rep Power
    3

    Default Re: Array list help

    Basically i helped you a bit with your structure here: fill in the gaps yourself:
    remember to import things you need!
    Java Code:
    import java.util.*; - holds the arrayList objects and methods
    public class XXXX {
    
        /*delcare variables*/
        private List<Order> waitingList;
        private List<Order> deliveredList; //private so they belong to this class and can be access by any method in XXXX 
        private int numberOfOrders; 
    
        public  DeliveryLog(int dd, int mm, int yy) 
        {
    
            numberOfOrders = 0;
            logDate = new Date(dd,mm,yy);
            //now create the waitingList array list should be simple, base it off of the private "items"
           //now create the deliveredList array list should be simple, base it off of the private "items"
        }
    
        public void addOrder (Order x)
        {
           //do what you want here, but remember it needs Object x passed into it so maybe search array and in another method
    //and pass the result into this method. think about that
            waitingList.add(x);
            numberOfOrders = numberOfOrders ++;
        } 
    
    }
    make sure each method has a return type, and make sure it has its own block {} otherwise it will not be happy!
    Last edited by monkeyjr97; 12-02-2012 at 01:20 AM.

Similar Threads

  1. Array List
    By turtlish in forum New To Java
    Replies: 10
    Last Post: 12-20-2011, 09:48 PM
  2. Linked List, Array List time complexity
    By Rick99771977 in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 06:37 AM
  3. Replies: 2
    Last Post: 09-06-2010, 02:03 AM
  4. Array List
    By mashyum in forum Advanced Java
    Replies: 2
    Last Post: 07-28-2009, 07:47 AM
  5. using an Array list
    By toad in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 10:08 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
  •