I can not figure out what is wrong with my code I have looked over it many times and cant find anything wrong with it. When I run the program it doesn't sort the list by the Item Id.
this is my tester class
import java.util.*;
public class Tester
{
public static void printInvetory(List<Item> a)
{
System.out.println("ItemID ItemName InStoreID Price");
System.out.println("-------------------------------------------");
for(int i = 0; i < a.size(); i++)
{
System.out.println(a.get(i));
}
}
public static void sortID(List<Item> a)
{
int i;
int k;
int posmax;
Item temp;
for(i = a.size() - 1; i >= 0; i--)
{
posmax = 0;
for(k = 0 ; k <= i ; k++)
{
if(a.get(k).getItemID() > a.get(posmax).getItemID())
posmax = k;
}
temp = a.get(i);
a.set(i, a.get(posmax));
a.set(posmax, temp);
}
}
public static void main(String[] args)
{
List<Item> myStore = new ArrayList<Item>();
myStore.add(new Item(0004, 200, 10.5, "Air Filters"));
myStore.add(new Item(0002, 60, 21.5, "Door Knobs"));
myStore.add(new Item(0006, 90, 9.99, "Hammers "));
myStore.add(new Item(0001, 80, 19.99, "Levels "));
myStore.add(new Item(0005, 100, 59, "Ceiling fans"));
myStore.add(new Item(0003, 55, 80, "Wrench Sets"));
printInvetory(myStore);
System.out.println();
printInvetory(myStore);
}
}
this is my constructor class
public class Item
{
private int itemID;
private int inStore;
private double Price;
private String itemName;
public Item(int id, int is, double p, String in)
{
itemID = id;
inStore = is;
Price = p;
itemName = in;
}
public String getName()
{
return itemName;
}
public int getItemID()
{
return itemID;
}
public int getInStore()
{
return inStore;
}
public double getPrice()
{
return Price;
}
public String toString()
{
return itemID + "\t" + itemName + "\t" + inStore + "\t" + "$ " + Price;
}
}
PLZ HELP.