I am trying to sort the data in the array.
I have already created a method that sorts the data but for some reason, I can not call this method correctly in the main
method.
Something doesn't work. The driver
class has to call up the method and send in the correct parameters. I tried to do so but it doesn't work. Something is wrong with the parameters. This program is supposed to receive data and sort it.
public class Kennel
{
public static <T extends Comparable<T>>
void selSort(T[] doggy)
{
//local variables
T temp;
Dog doggy[ ] = new Dog [MAX_DOGS]; //dog array
int outerLoop; // Outer loop counter
int innerLoop; //Inner loop counter
int location; //Location of smallest value
int n = doggy.length; //number of items in the array
/***************************************************/
for (outerLoop = 0; outerLoop < n - 1; outerLoop++)
{
//
location = outerLoop;
//
for (innerLoop = outerLoop + 1; innerLoop < n; innerLoop++)
{
if (doggy[location].compareTo((doggy[innerLoop])) > 0)
{
location = innerLoop;
}//end IF
}//end FOR
>swap the value of the old smallest with the value of the new smallest<
T iSwap = doggy[location];
doggy[location] = doggy[outerLoop];
doggy[outerLoop] = iSwap;
}//end FOR
}//end selSort
main method
public static void main(String args[])
{
mid = new Kennel();
mid.selSort(mid.doggy);
}
When I compile the code I get an error:
117: error: method selSort in class Kennel cannot be applied to given types;
mid.selSort(mid.doggy);
^
required: T[]
found: Dog[]
reason: inferred type does not conform to upper bound(s)
inferred: Dog
upper bound(s): Comparable<Dog>
where T is a type-variable:
T extends Comparable<T> declared in method <T>selSort(T[])
1 error
Not sure how to fix this problem.