Results 1 to 13 of 13
  1. #1
    alexisasoxfan is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default Help with arraylist

    import java.util.*;

    public class Test {

    private ArrayList<Flight> a;

    public Trip (ArrayList<Flight> c) {

    a = c;

    }
    }


    How come it won't let me set up the constructor this way... I'm having trouble with this. Do I need to use a loop?

  2. #2
    alexisasoxfan is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    even though the constructor is there, on the test class my teacher provided, it says it's missing!

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Your class is called Test, but your constrictor is called Trip().

    -Gary-

  4. #4
    alexisasoxfan is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    I fixed that, but it still doesn't work. Is there another way to initialize arraylists in constructors?

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    What you have looks fine to me. There is a Flight class, right?

    EDIT: Tell us what error you're getting from the compiler.

    -Gary-

  6. #6
    alexisasoxfan is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    The test class says, *** Failed: missing constructor Test(ArrayList<Flight> c)

    yeah the Flight class exists everything and works fine.

  7. #7
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Copy and paste the code you just tried to compile. Please use CODE tags.

    -Gary-

  8. #8
    alexisasoxfan is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    * Flight class for Flight List Project
    *
    * @author
    */
    public class Flight
    {
    // instance variables - replace the example below with your own
    private String num;
    private Time departure;
    private Time arrival;

    /**
    * Constructor for objects of class Flight
    */
    public Flight(String f, Time d, Time a)
    {
    num = f;
    departure = d;
    arrival = a;

    }

    public void setFlight (String f, Time d, Time a) {
    num = f;
    departure = d;
    arrival = a;
    }

    public Time getDepartureTime() {

    return departure;

    }

    public Time getArrivalTime() {

    return arrival;

    }

    public String toString() {

    int x = departure.getHours();
    int a = arrival.getHours();
    int test = (x - a) * 60;
    int test_2 = test + (departure.getMinutes() - arrival.getMinutes());

    return num + "-" + departure + "-" + arrival + "-" + test_2;

    }

    }


    import java.util.*;

    public class Test {

    private ArrayList<Flight> a;

    public Test (ArrayList<Flight> c) {

    a = c;

    }
    }
    Last edited by alexisasoxfan; 05-07-2010 at 03:08 AM.

  9. #9
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    "test" is not "Test".

    -Gary-

  10. #10
    alexisasoxfan is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    I fixed it, still doesn't work. do you see anything else?

  11. #11
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Take the ArrayList out of the equation temporarily. Change the instance variable and constrictor parameter to simple int variables. One you get that to compile, change them back to ArrayList.

    -Gary-

  12. #12
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    are both the files in the same folder?

  13. #13
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    can you give us the test class? and correct error from the compiling console.

Similar Threads

  1. ArrayList
    By rusBoy in forum Advanced Java
    Replies: 1
    Last Post: 11-12-2009, 11:36 AM
  2. Regarding arrayList
    By kishan in forum Advanced Java
    Replies: 7
    Last Post: 08-07-2009, 12:48 PM
  3. Replies: 2
    Last Post: 04-21-2008, 11:43 AM
  4. ArrayList
    By kizilbas1 in forum New To Java
    Replies: 11
    Last Post: 12-05-2007, 07:30 PM
  5. New to arraylist
    By kleave in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 06:45 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
  •