I have this toString method set up
public String toString (){
String result;
result = "Ideal Family";
result += "\n"+person1.toString();
result += "\n"+person2.toString();
result += "\n"+person3.toString();
result += "\n"+person4.toString();
result += "\n"+pet1.toString();
result += "\n"+car1.toString();
result += "\n"+car2.toString();
result += "\n"+homeAddress.toString();
return result;
}
in which I list objects in the order I wish to output them. Is there a way to re-order the list based on values within the objects.
Specefically in the Person Class, to re-order the person objects based on an instance variable, an int.
The Person class takes these parameters
public Person (String personName,String personGender,String personSS,int personAge){
name = personName;
ss = personSS;
age = personAge;
gender = personGender;
}
First of all, you should be using a collection instead of having four variables. It would have been easier.
But for what you are looking for, create a list of
Personssort the list
and iterate through the list