• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with sort code

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
}
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Monic Sherm
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}
}
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Declaration:

Call:


selectionSort is only defined for Comparable[] not for String. So you need to create the array first.
 
Monic Sherm
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anyone can help me with this code, I would really appreciate it

Thanks in advance
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic