Help with a method that SHOULD work....
Let me start by saying I'm a newbie. I'm taking a JAVA class and our assignment started with writing a DVD Inventory program that used 2 classes, 1 class sets up the inventory attributes (caled inventory.class) and another called inventoryTest that you run to display the contents of the inventory class.
In part 2, we modified the inventoryTest class to use an array of an object of the inventory class. This way we could display more than 1 DVD in the program. We also had to be able to sort the list NOT using the array.sort utility.
My professor sent me a method to use to resort my DVD array. He wrote it as follows:
public product[] SortInventory.length(product[] theInventory)
{
product tmp;
for (int i = 0; i < theInventory.length; i++)
{
for (int j = i + 1; j < theInventory.length; j++)
{
String s1 = theInventory.getItemName();
String s2 = theInventory[j].getItemName();
if(s1.compareTo(s2)>0)
{
tmp = theInventory;
product = theInventory[j];
product[j] = tmp;
}
}
}
return theInventory;
}
I cannot get this method to work. I assume that it has to go in the inventoryTest class because it has the main method in it. The compiler keeps wanting to treat it like a class. The parts that say getItemName I actually replaced with getTitle which is the method that returns the DVD title which is what I'm supposed to alphabetize by.
I know this is probably very confusing, but when I compile my program with this code, it does not like the method declaration first and foremost and since this came directly from my professor I think it should work.
Any advice would be appreciated.
You can also iChat me at dhooie@mac.com
Thanks in advance to anyone.
David Hooie

