aspose file tools*
The moose likes Beginning Java and the fly likes help with sort code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with sort code" Watch "help with sort code" New topic
Author

help with sort code

Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
I am unable to compile this code. I am trying to sort by author with the code. The error message says it is looking for a symbol for inventorySort which is the class that I created to do the sort. Any help would be appreciated.

Thanks in advance

//The main driver class for the Bookstore Inventory



import java.util.Scanner;
import java.io.*;

public class BookInventory
{
public static void main (String[] args) throws IOException
{
String inventory;
Scanner fileScan, InventoryScan;


Book[] bookData = new Book[500];
fileScan = new Scanner (new File ("inventory.txt"));


while (fileScan.hasNext())
{
inventory = fileScan.nextLine();
System.out.println(inventory);


InventoryScan = new Scanner (inventory);
InventoryScan.useDelimiter("/");

inventorySort.selectionSort(inventory);
System.out.println(inventory);
}
}
}
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
Where in this class do you create inventorySort. I was looking for something like
InventorySort inventorySort = new InventorySort();

or

is selectionSort(inventory) a static method in the InventorySort class? In that case I'd guess that you need to be more aware of Java's case sensitivity.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
This is the inventorySort class that I created. Any advice would be greatly appreciated


public class inventorySort
{

//-----------------------------------------------------------------
// Sorts the specified array of objects using the selection
// sort algorithm.
//-----------------------------------------------------------------
public static void selectionSort (Comparable[] list)
{
int min;
Comparable temp;

for (int index = 0; index < list.length-1; index++)
{
min = index;
for (int scan = index+1; scan < list.length; scan++)
if (list[scan].compareTo(list[min]) < 0)
min = scan;

// Swap the values
temp = list[min];
list[min] = list[index];
list[index] = temp;
}
}
}
Vlado Zajac
Ranch Hand

Joined: Aug 03, 2004
Posts: 245
Declaration:

Call:


selectionSort is only defined for Comparable[] not for String. So you need to create the array first.
Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
I guess I am confused, I thought that I declared the array as

Book[] = new Book [500]

the list is in the inventory.txt file.

Any help would be greatly appreciated.

Thanks
Monic Sherm
Greenhorn

Joined: Sep 30, 2005
Posts: 13
If anyone can help me with this code, I would really appreciate it

Thanks in advance
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Vlado is right. Your method selectionSort takes a Comparable[] parameter:



But you are passing inventory which a String object:



So Java is looking for a method like this:



which you haven't declared.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help with sort code