Re: iterating through an array of String's
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@arrakis:~/bcit-comp2611-lab2$
thufir@arrakis:~/bcit-comp2611-lab2$ cat src/a00720398/labs/Task.java
//Task.java
//this class is required to be the "meat" of lab2
package a00720398.labs;
import a00720398.data.*;
import 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@bcit.ca" },
{ "Sullivan", "Sam", "604-873-7011", "Sam777@hotmail.com" },
{ "Johansen", "Lars", "(604) 636-1000", "Lars147@gmail.com" }},
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@arrakis:~/bcit-comp2611-lab2$
thanks,
Thufir