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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with incompatable types error 1

Status
Not open for further replies.

Salamander014

Programmer
Mar 3, 2009
3
US
im getting an incompatable types error in my code below.
its supposed to sort CoinNoob objects in order of lowest value to highest. Each CoinNoob has a val, the value, and it is public. any help??
Code:
import java.util.ArrayList;
public class CoinSorter
{
	public CoinSorter(ArrayList<CoinNoob> anArrayList)
	{
		for(CoinNoob s: anArrayList)
			a.add(s);
	}
	public void sort()
	{
		for(int i = 0; i < a.size()-1; i++)
		{
			int minPos = minimumPosition(i);
			swap(minPos, i);
		}
	}
	public int minimumPosition(int from)
	{
		int minPos = from;
		for(int i = from + 1; i < a.size(); i++)
		{
			CoinNoob b;
        //right here...............
			b = a.get(i);
			if(b.val < b.val)
				minPos = i;
		}
		return minPos;
	}
	private void swap(int i, int j)
	{
		a.set(j,a.set(i, a.get(j))); 
	}
	private ArrayList a = new ArrayList<CoinNoob>();
}
 
Your should replace

private ArrayList a = new ArrayList<CoinNoob>();

by

private ArrayList<CoinNoob> a = new ArrayList<CoinNoob>();

BTW: using a Comparator is an easier way to sort elements in an ArrayList
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top