DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: how to pass args to an object array?

  1. #1
    Join Date
    Aug 2002

    Question how to pass args to an object array?

    I am very new at java and in route for a lot of headaches. I'm trying to write a small Geo quiz program that will define countries as objects (the variables will be cities, language, presidents, etc..) and quiz the user.
    Well I've spent 2 days looking and snooping around and I still can't figure out how to build an array of objects the same way I do it with String[].

    This is my approach:

    1> I've created an object Country() representated as Country(String A, String B, String C, StringD) where A,B,C,D are city, language, money and pdt. it works fine.

    2> Build 20 countries on that model:
    Country A =new Country ("Australia","Sydney","Dollar");
    Country B =new Country("Bolivia","La Paz","Dinero");
    Country T =new Country("Texas","Austin","Dollar); and so on

    3> now I create an array to put 20 countries in and quiz the user:
    Country[] myList = new Country[10];
    myList =(A,B,C,D,E....T);

    and that's where my problem is.
    Please help!!!!

  2. #2
    Join Date
    Jul 2002

    Country[] c = new Country[] {
    new Country( "", "", "" ),
    new Country( "", "", "" ),
    new Country( "", "", "" )

    (not compile nor tested)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center