Image

Imagecountessfemgeek wrote in Imagejava_dev 😡frustrated

arrrg.. HELP PLEASE (=

hello, i'm a bit new here... was wondering if anyone could help

I am trying to use a Comparable Interface to sort objects of an arrayList
and everything functions and compiles except the sorting statement which returns the error:
"insertionSort(java.lang.Comparable) in Sorts cannot be applied to (java.util.ArrayList)"



3 classes
1. Account which implements Comparable
& contains the following compareTo() method


public int compareTo(Object object)
{
int acctNumResult;
if (AccountNumber <= ((Account)object).AccountNumber)
acctNumResult = 1;
else
acctNumResult = -1;

return acctNumResult;
}

2. Sorts which contains the method to sort the account numbers in increasing order

public static void insertionSort(Comparable objects)
{
for (int i = 0; i < Bank.myBank.size(); i++)
{
Comparable thing = (Account)Bank.myBank.get(i);
int position = i;
Comparable thing2 = (Account)Bank.myBank.get(position - 1);
Comparable thing3 = (Account)Bank.myBank.get(position);

//shift larger values to right
while ( position > 0 && thing2.compareTo(thing) > 0 )
{
thing3 = thing2;
position--;
}
thing3 = thing;
}
}

3. Bank which creates the arrayList myBank containing the accounts

Sorts.insertionSort(myBank); //statement NOT working.. returns error mentioned above
//casting and get methods do not work here, i'm not sure what else to try


i'm sure there's a simple solution i'm completely missing b/c i've looked at this too long
any suggestions would be greatly appreciated!! thanx in advance!