Salamander014
Programmer
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??
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>();
}