HI,
I've created a Comparable interface class Person. Which has variables First_name, surname, month(Of birth), day(Of birth) , and birthday(which i have created from month and day). I have a compareTo method which will compare two person objects by the birthday. If the birthday are the same it outputs int 0, if one is bigger it outputs int 1 and if the other one is bigger it outputs int -1. I have also created an arraylist called people, which holds objects of person. Now i am trying to create a selection sort method which will sort the objects into birthday order, here is the code i have so far but am really stumped on what to do now...
import java.util.Array List.*;
public class Main
{
public static void selectionSort(C omparable[] people)
{
for (int k = people.length-1; k>0; k --)
{
Comparable tmp;
int Large = 0;
for (int j=1; j<= k; j++)
{
if (people[j].compareTo(peop le[k]) <0)
{
Large = j;
}
tmp = people[Large];
people[Large] = people[k];
people[k] = tmp;
}
}
}
}
Any help would be brilliant,
Thanks a lot
Dave
I've created a Comparable interface class Person. Which has variables First_name, surname, month(Of birth), day(Of birth) , and birthday(which i have created from month and day). I have a compareTo method which will compare two person objects by the birthday. If the birthday are the same it outputs int 0, if one is bigger it outputs int 1 and if the other one is bigger it outputs int -1. I have also created an arraylist called people, which holds objects of person. Now i am trying to create a selection sort method which will sort the objects into birthday order, here is the code i have so far but am really stumped on what to do now...
import java.util.Array List.*;
public class Main
{
public static void selectionSort(C omparable[] people)
{
for (int k = people.length-1; k>0; k --)
{
Comparable tmp;
int Large = 0;
for (int j=1; j<= k; j++)
{
if (people[j].compareTo(peop le[k]) <0)
{
Large = j;
}
tmp = people[Large];
people[Large] = people[k];
people[k] = tmp;
}
}
}
}
Any help would be brilliant,
Thanks a lot
Dave
Comment