Hi, I have a small question regarding arrays. I have the class Family below:
import java.util.ArrayList;
import java.util.Collection;
import java.io.*;
public class Family
{
private Adult father;
private Adult mother;
private Child[] children;
private Dog ourDog;
private Cats ourCat;
private Rabbit ourRabbit;
int Age;
public Family()
{
}
public Family(Adult father, Adult mother, Child[] children)
{
setFather(father);
setMother(mother);
setChildren(children);
ourDog=new Dog("");
ourCat=new Cats("");
ourRabbit = new Rabbit("");
}
private Adult getFather()
{
return this.father;
}
private Adult getMother()
{
return this.mother;
}
private Child[] getChildren()
{
return this.children;
}
private void setFather(Adult father)
{
this.father = father;
}
private void setMother(Adult mother)
{
this.mother = mother;
}
private void setChildren(Child[] children)
{
this.children = children;
}
public Collection getMovieGoers(int rating)
{
ArrayList mGoers = new ArrayList();
// I consider rating here to be the starting age that is allowed for the movie
if ( father.getAge() >= rating)
mGoers.add(father);
if ( mother.getAge() >= rating)
mGoers.add(mother);
for(int i = 0; i < children.length; i++)
{
if (children[i].getAge() >= rating)
mGoers.add(children[i]);
}
return mGoers;
}
public static void main(String args[])throws IOException
{
MovieRating mRt = new MovieRating();
Child[] children = {new Child("Frank",10), new Child("Lisa",18)};
Family fam = new Family(new Adult("John",37), new Adult("Mary",35),children);
ArrayList mvGoers= (ArrayList)fam.getMovieGoers(mRt.getAdult());
System.out.println("Movie goers: "+mvGoers+"");
//pets
fam.ourCat.catType("Angora");
fam.ourCat.setCatColor("Brownish white");
fam.ourDog.dogType("African Shepherd Dog");
fam.ourDog.setDogColor("Black");
fam.ourRabbit.setRabbitColor("White");
fam.ourRabbit.rabbitType("Akorino");
System.out.println("We own the following pets: " +
" " + fam.ourDog.MydogType+ " " + fam.ourDog.dog_color + " in color;" +
" a small " + fam.ourCat.cat_color + " " +fam.ourCat.MyCatType+ " cat;"+
" and a "+ fam.ourRabbit.rabbit_color +" "+ fam.ourRabbit.MyRabbitType +
" rabbit.");
}
}
In the constructor for Family(Adult father, Adult mother, Child[] children), I have father, mother (both Adult) and Child[] which is an array of chidren.
The problem is in the main method:
Child[] children = {new Child("Frank",10), new Child("Lisa",18)};
Family fam = new Family(new Adult("John",37), new Adult("Mary",35),children);
ArrayList mvGoers= (ArrayList)fam.getMovieGoers(mRt.getAdult());
System.out.println("Movie goers: "+mvGoers+"");
When I run the application this is what I get in the last line
Movie goers: [myinheritancepolymorph.Adult@1a46e30, myinheritancepolymorph.Adult@3e25a5]
any help on how to modify the code so that it can print out all the family members.
NOTE: Other sections have no problem except this array section.