comparable
hi
im trying to implement the comparable interfact to print out information about people in aplhabetical order
iv tried to write the code and it compiles however the information is still not being printed out in alphabetical order
i would appreciate it if anyone could look at my code and tell me where im going wrong
thanks
person class
publicclass Person
{
public String surname, firstname;
publicint age, weight;
publicdouble height;
public Person()
{
}
public Person(String firstname, String surname,int age,double height,int weight)
{
this.firstname = firstname;
this.surname = surname;
this.age = age;
this.height = height;
this.weight = weight;
}
public String getFirstname()
{
return firstname;
}
public String getSurname()
{
return surname;
}
publicint getAge()
{
return age;
}
publicdouble height()
{
return height;
}
publicint weight()
{
return weight;
}
}
[b]playerclass[/b]
[code]
publicclass Playerextends Personimplements Comparable<Player>
{
publicint gamesplayed, runsscored, timesdismissed;
public Player(String firstname, String surname,int age,double height,int weight,int gamesplayed,int runsscored,int timesdismissed)
{
super(firstname, surname, age, height, weight);
this.gamesplayed = gamesplayed;
this.runsscored = runsscored;
this.timesdismissed = timesdismissed;
}
publicint getGamesplayed()
{
return gamesplayed;
}
publicint getRunsscored()
{
return runsscored;
}
publicint getTimesdismissed()
{
return timesdismissed;
}
public Player(String firstname, String surname)
{
setfirstname(firstname);
setsurname(surname);
}
publicint compareTo(Player p)
{
return (getsurname() + getfirstname()).compareTo(p.getsurname() + p.getfirstname());
}
public String getfirstname()
{
return firstname;
}
publicvoid setfirstname(String firstname)
{
this.firstname = firstname;
}
public String getsurname()
{
return surname;
}
publicvoid setsurname(String surname)
{
this.surname = surname;
}
public String getDetails()
{
return"Firstname = " + firstname +" Surname = " + surname +" Age = " + age +" Height = " + height +"m Weight = " + weight +"kg Games Played = " + gamesplayed +" Runs Scored = " + runsscored +" Times Dismissed = " + timesdismissed;
}
}

