DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2002
    Posts
    2

    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
    Posts
    17
    eg,

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

    (not compile nor tested)

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links