I am trying to pass an array as a parameter of a constructor in my program. Entry is a class used to modify the objects amy and brian instance variables. Addressbook is a class that includes the main method, that sets each Entry() objects data and then modifies it. Also within this program I am attempting to create an array to store each object. The goal is to create a constructor that takes an array of Entry objects and initializes an AddressBook object. Then I must add other methods but I cannot get the constructor and array to link.
Below is the code, I am trying to pass the array Entry[] Contact through the Addressbook constructor and am getting the error at line 7 that its expecting a ; or .class.
<code>
import java.util.Scanner;
public class Addressbook
{
private Entry[] e;
public Addressbook contact = new Addressbook(Entry[] Contact)
{
e = new Entry[1];
for (int i = 0; i <= 1; i++)
{
e[i] = Contact[i];
}
}
public static void main(String[] args)
{
Entry amy = new Entry();
amy.set("Amy", "Angel", "1504 North 18th Street Philadelphia PA 19121", "2155958296", "stupidPrinc$
amy.writeOutput();
amy.set("Amy", "Angel", "202 West 1st Street Los Angeles CA 90012", "2132375000", "stupidLAgirl@ge$
amy.writeOutput();
Entry brian = new Entry();
brian.set("Brian", "Boring", "1501 Carlisle Street Philadelphia PA 19122", "2158649080", "BoringAs$
brian.writeOutput();
brian.set("Brian", "Boring", "225 Baker Street NOrthwest Atlanta GA 30313", "4045814000", "StillBo$
brian.writeOutput();
Entry[] Contact = new Entry[1];
Contact[0] = amy;
Contact[1] = brian;
Addressbook contact = new Addressbook(Contact);
contact.e[0] = amy;
contact.e[1] = brian;
}
}
</code>
Hello!
I am trying to pass an array as a parameter of a constructor in my program. Entry is a class used to modify the objects amy and brian instance variables. Addressbook is a class that includes the main method, that sets each Entry() objects data and then modifies it. Also within this program I am attempting to create an array to store each object. The goal is to create a constructor that takes an array of Entry objects and initializes an AddressBook object. Then I must add other methods but I cannot get the constructor and array to link.
Below is the code, I am trying to pass the array Entry[] Contact through the Addressbook constructor and am getting the error at line 7 that its expecting a ; or .class.
import java.util.Scanner;
public class Addressbook
{
private Entry[] e;
public Addressbook contact = new Addressbook(Entry[] Contact)
{
e = new Entry[1];
for (int i = 0; i <= 1; i++)
{
e[i] = Contact[i];
}
}
public static void main(String[] args)
{
Entry amy = new Entry();
amy.set("Amy", "Angel", "1504 North 18th Street Philadelphia PA 19121", "2155958296", "stupidPrinc$
amy.writeOutput();
amy.set("Amy", "Angel", "202 West 1st Street Los Angeles CA 90012", "2132375000", "stupidLAgirl@ge$
amy.writeOutput();
Entry brian = new Entry();
brian.set("Brian", "Boring", "1501 Carlisle Street Philadelphia PA 19122", "2158649080", "BoringAs$
brian.writeOutput();
brian.set("Brian", "Boring", "225 Baker Street NOrthwest Atlanta GA 30313", "4045814000", "StillBo$
brian.writeOutput();
Entry[] Contact = new Entry[1];
Contact[0] = amy;
Contact[1] = brian;
Addressbook contact = new Addressbook(Contact);
contact.e[0] = amy;
contact.e[1] = brian;
}
}

New Topic/Question
Reply



MultiQuote






|