Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

the compiler is calling my Comparable an int

Status
Not open for further replies.

confission

Programmer
Sep 28, 2002
10
US
i keep getting the following error. it says it's found an int, but the heap is made up of Comparables, so i don't get it.

WorstFit.java:36: inconvertible types
found : int
required: java.lang.Comparable
if ((Comparable)(new Integer(s)).compareTo(myHeap.heap[1])<=0)



(the &quot;^&quot; is pointing at the &quot;(&quot; after &quot;compareTo&quot;)


here's the code, if it helps:

package dataStructures;
import java.util.*;

public class WorstFit
{

//s <= c for all i
public static void worstFitPack(int []s, int c)
{

//output packing information one by one


int j=1;

MaxHeap myHeap=new MaxHeap(s.length);

if (s[1]>c)
{
throw new IllegalArgumentException(&quot;an element in the array is bigger than the capacity of the containers&quot;);
}

myHeap.put((Comparable)(new Integer(s[1])));


for (int i=2; i<s.length; i++)
{

if (s>c)
{
throw new IllegalArgumentException(&quot;an element in the array is bigger than the capacity of the containers&quot;);
}



if ((Comparable)(new Integer(s)).compareTo(myHeap.heap[1])<=0)
{
Comparable previousAmount=myHeap.heap[1];
MyHeap.put((Comparable)((int)myHeap.removeMax())-((int)element));

System.out.println(+element[1] +&quot;is added to container with &quot; +previousAmount +&quot;. container now holds &quot; +myHeap.heap[1]);


}

else
{
myHeap.put((Comparable)(c-((int)(element))));

System.out.println(&quot;new container holds &quot; +element);

}

}
}


// test

public static void main(String []args)
{
int n = 10;

int c = 99;

int [] s = {0, 22, 84, 97, 47, 20, 64, 43, 11, 56, 96}; //s[0] is not used

WorstFit.worstFitPack(s, c);
}
}
 
nevermind. i put some more parentheses in and it works now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top