Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: iterating t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 11 Topic 15994 of 16566
Post > Topic >>

Re: iterating through an array of String's

by thufir <hawat.thufir@[EMAIL PROTECTED] > Apr 21, 2008 at 07:58 AM

On Sun, 20 Apr 2008 10:05:35 +0000, Roedy Green wrote:

>>  private final static String[][] DATA = {
>>                {"00", "01", "02", "03"},
>>                {"10", "11", "12", "13"},
>>                {"20", "21", "22", "23"},};
> 
> to iterate through a doubly dimensioned array, see
> 
> http://mindprod.com/jgloss/array.html#MATRIXGOTCHAS

I've looked around, but haven't found the information I was looking for 
yet.  Strictly looking at the syntax for assigning a row of ADDRESS_DATA
to the address object, is there a more compact syntax?

thufir@[EMAIL PROTECTED]
 
thufir@[EMAIL PROTECTED]
 cat src/a00720398/labs/Task.java 
//Task.java

//this class is required to be the "meat" of lab2

package a00720398.labs;
im****t a00720398.data.*;
im****t java.util.*;

public class Task
{
        private ArrayList<Guest> guests;

        private Guest guest;

	//these three objects should consolidated to one object:
        Address address;
        ContactInfo contactInfo;
        Name name;


        //it's required to load data from these arrays

                  private final String[][]

        GUEST_DATA = {
        { "Lee", "Brenda", "(604) 636-1000", "b.lee@[EMAIL PROTECTED]
" },
        { "Sullivan", "Sam", "604-873-7011", "Sam777@[EMAIL PROTECTED]
" },
        { "Johansen", "Lars", "(604) 636-1000", "Lars147@[EMAIL PROTECTED]
" }},


        ADDRESS_DATA = {
        { "3700 Willingdon Avenue", "Burnaby", "British Columbia",
        "V5G 3H2", "Canada" },
        { "453 West 12th Avenue", "Vancouver", "BC", "V5Y 1V4", 
         "Canada"  },
        { "1000 Lougheed Highway", "Coquitlam", "British Columbia",
        "V3K 3T5", "" } };


        //creates new instances of each Guest attribute
        //It might be better to treat name, contactInfo and address
        //as mutatable.  Not a major point.
        public Guest newGuest(int row){
                name = new Name(GUEST_DATA[row][0], GUEST_DATA[row][1]);
                contactInfo = new ContactInfo(GUEST_DATA[row][2],
                GUEST_DATA[row][3]);

                //apparently there's a trick to assign an entire
                //row with one go?
                address = new 
                 Address(ADDRESS_DATA[row][0],ADDRESS_DATA[row][1],
                
                ADDRESS_DATA[row][2],ADDRESS_DATA[row][3]
                ,ADDRESS_DATA ,[row][4]);
                Guest guest = new Guest(name,contactInfo,address);
                return guest;
        }

        public void loadArray() {
                guests = new ArrayList<Guest>();
                for (int i=0; i<3; i++) {
                        guest = newGuest(i);
                        guests.add(guest);
                }
                System.out.println(guests);
        }
}
thufir@[EMAIL PROTECTED]
 




thanks,

Thufir
 




 11 Posts in Topic:
iterating through an array of String's
thufir <hawat.thufir@[  2008-04-20 08:50:00 
Re: iterating through an array of String's
Roedy Green <see_websi  2008-04-20 10:04:03 
Re: iterating through an array of String's
Thufir <hawat.thufir@[  2008-04-30 03:43:18 
Re: iterating through an array of String's
Roedy Green <see_websi  2008-04-20 10:05:35 
Re: iterating through an array of String's
voorth <voorth@[EMAIL   2008-04-21 03:51:03 
Re: iterating through an array of String's
Lew <lew@[EMAIL PROTEC  2008-04-21 07:12:00 
Re: iterating through an array of String's
thufir <hawat.thufir@[  2008-04-21 07:58:23 
Re: iterating through an array of String's
thufir <hawat.thufir@[  2008-04-21 10:34:52 
Re: iterating through an array of String's
Ian Kidder <ikidder@[E  2008-04-22 06:44:11 
Re: iterating through an array of String's
thufir <hawat.thufir@[  2008-04-23 04:06:25 
Re: iterating through an array of String's
Lew <lew@[EMAIL PROTEC  2008-04-23 00:19:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 15:42:14 CST 2008.