Hi Ken, Adrian's hunch was correct and I'm headed forward again. Thanks for having a look.
Best, JW Ken Perry wrote:
Did you try what the other person suggested with the -1, 1, and 0 returns? Do you have the simple compiled version you were playing with if you do I finally got Java up and running on my Vista box and would be willing to take a look. Now to go install Mingw man getting a computer up and running again is work. Next I have to rebuild the Linux box. Ken -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jared Wright Sent: Friday, November 28, 2008 10:34 PM To: programmingblind@xxxxxxxxxxxxx Subject: Re: Java: Using Comparable to Establish Natural OrderHi Ken, I'd done a little isolation in the hopes of finding my error (mostly by making an array of items and calling sort), although with no breakthrough. Never can hurt to play more, so I'll do so with your suggestions in mind. Thanks for having a look at this.Best, jW Ken Perry wrote:I looked at the code and it looks right unfortunately I haven't installed the Java sdk on this new box so I can't compile it. My suggestion is makeasimple test maybe use your Icomparible code in a simple list outside ofthelarger application and test it to make sure it's doing what you think it's supposed to. Then go to the queue.. I am getting started installing the java sdk on Vista right now hopefully it will go smoothly and then I willbeable to take a look closer. Make sure you print values all over the place when testing it and you will more quickly catch the error. Ken -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jared Wright Sent: Friday, November 28, 2008 7:16 PM To: programmingblind@xxxxxxxxxxxxx Subject: Re: Java: Using Comparable to Establish Natural OrderNope. Had migrated to other bits and pieces of code in the little bit of time I had on Thanksgiving. Would still appreciate any thoughts or suggestions you might have.JW Ken Perry wrote:Did you get this working I am just now catching up with mail. Ken -----Original Message----- From: programmingblind-bounce@xxxxxxxxxxxxx [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jared Wright Sent: Thursday, November 27, 2008 12:28 PM To: programmingblind@xxxxxxxxxxxxx Subject: Java: Using Comparable to Establish Natural OrderHi all, I've used comparable before, but with this go 'round I have found I must be missing something. I'm trying to use Comparable to establish the natural order of an Item class. Each item has a cost, size, and with these two values, the "value" of the item can be calculated. I wish for this value metric to be the index for the items' natural ordering, so priority queues and collection sorting methods will use this to order item objects. With the below code, my items are all returned to me from a priority queue simply in the reverse order they were added to the queue. Suggestions aappreciated, and I'll give much thanks on this of all days for any help! *grin* I am trying to have it order items with highest values first.Best, JW // Class representing an item. class Item implements Comparable { private double cost=0; private double size=0; public Item(double dCost, double dSize) { cost = dCost; size = dSize; } public double getCost() { return cost; } public double getSize() { return size; } public double getValue() { return cost/size; } public int compareTo(Object oItem) { double oItemValue = ((Item)oItem).getValue(); double result = ((this.getValue()))-oItemValue; return (int)result; } } __________View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind__________View the list's information and change your settings at //www.freelists.org/list/programmingblind
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind