This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

help with sort code  RSS feed

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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: 9087
12
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!