CompareTo() issues Sorting

Hello I am fairly new to Java but I have been working with it for about 6 months, I am trying to sort multiple arrays in a non-GUI program. The user inputs the infomation into these arrays :
arrayProductNumber[]
arrayName[]
arrayUnitsInStock[]
arrayUnitPrice[]
so I set up a sort method using compareTo to sort the arrayName and if the arrayName "moves" so does the rest. Here is the code that I have, I'm not getting any errors the program runs perfectly fine but the sort is not working at all. HELP!
     public static void sortStrings()
          int j = 0, k = 0;
          for(k=0; k<arrayName.length; k++)     
               for(j=k+1; j<arrayName.length; j++)
                    if(arrayName[k].compareTo(arrayName[j])<0)
                         temp=arrayName[j];
                         arrayName[j]=arrayName[j+1];
                         arrayName[j+1]=temp;
                         hold=arrayProductNumber[j];
                         arrayProductNumber[j]=arrayProductNumber[j+1];
                         arrayProductNumber[j+1]=hold;
                         hold=arrayUnitsInStock[j];
                         arrayUnitsInStock[j]=arrayUnitsInStock[j+1];
                         arrayUnitsInStock[j+1]=hold;
                         hold=arrayUnitPrice[j];
                         arrayUnitPrice[j]=arrayUnitPrice[j+1];
                         arrayUnitPrice[j+1]=hold;
     }

FYI:
Thanks to the people who tried to help and thanks to the people who told me I was stupid, I got the program to work like this
     public static void sortStrings(String[] array, String[] array2, double[] product, double[] stock, double[] price, int len)
          int a,b = 0;
          String temp;
          double hold;
          int sort = len - 1;
          for(a=0; a<len; a++)
               for(b=0; b<sort; b++)
                    if(array.compareTo(array[b+1])>0)
                         temp=array[b];
                         array[b]=array[b+1];
                         array[b+1]=temp;
                         temp=array2[b];
                         array2[b]=array2[b+1];
                         array2[b+1]=temp;
                         hold=product[b];
                         product[b]=product[b+1];
                         product[b+1]=hold;
                         hold=stock[b];
                         stock[b]=stock[b+1];
                         stock[b+1]=hold;
                         hold=price[b];
                         price[b]=price[b+1];
                         price[b+1]=hold;
     }all by my little old self / and no it didn't take me this llong to do it I just forgot to tell you guys!
Edited by: pickil11 on Nov 1, 2008 7:01 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Will Iphone 4 8gb have antenna issue sorted?

    Hi ,
    I am hoping some one in this forum might get a inside information on the new Apple iphone 4 8gb which will be released on 14 oct with new ios  5  but no SIRI.
    Now I had a bad experience with the Iphone 4 white which I bought in June 2011 and returned back after suffering a lot of call drop issue because of antenna on the phone.
    I dont want to be in the same situation again where I buy the iphone 4 8gb and realize that the antenna issue still exists.
    SO MY QUESTION TO APPLE IS:
    IS THE ANTENNA GATE ISSUE SORTED OUT ON THE IPHONE 4 8GB ?
    Thank you

    Yes, I am talking about the GSM model. Cause a friend of mine had bought this model iphone 8gb a year back when Iphone was launched. But it was soon stopped. So he has got the iphone 8gb model and even he had issues with the antenna on it.
    Now I am just wondering if Apple has just launched the model back again without any changes to the antenna.
    I want to just use the 8gb one if it doesnt have any issues, till the time iphone 5 gets launched.
    I am waiting for the prices to be released tomorrow in UK. just to see what the contracts turn out to be.
    Why to buy the new Iphone 4s if that looks exactly same as the Iphone 4. Features matter, but iphone 5 is
    what I wanted to buy.

  • F110 Issue-sort code issue

    Hi Gurus,
    We have one issue by F110,by using the bank transfer.so all the payments are cleared.and DME file is generated.we have to upload to the bank.before that we have to convert the file into notepad.by using our local software we upload into our PC.but here
    some vendors are not picking up the right sort codes.on which base it is picking up.only for some vendors we are facing this issue.
    Thanks in advance
    Jana

    Dear,
    Please check the vendor master for the sort key entry in accounting information accounting, compare the sort key with other vendor masters. Check whether reconciliation GL in vendor master is also given the same sort key as in the vendor master.

  • Issue sorting dates in export to excel

    After exporting to excel, the end-user wants to sort on a date characteristic (posting date), using excel functionalities. This gives an incorrect result:
    01.01.2006
    01.01.2007
    01.02.2006
    01.02.2007
    If we sort on a time characteristic (calendar day), the list is sorted correctly.
    If we run the report via the BEx and then sort (using excel functionalities), it is also correct :
    01.01.2006
    01.02.2006
    01.01.2007
    01.02.2007
    How can we enable the correct sort?
    Thanks for your help!

    Dear Karthikeyan,
    I was also facing the same issue, and the reason was the diifferrence in the protocol of the J2EE WAS and that of Diapatcher.
    check whether J2EE WAS and that of Diapatcher are both on http or on https. If they both are not same, that's the issue.
    Hope it helps!!
    Warm Regards,
    Upendra Agrawal

  • TS2446 please help to find out this issue sorted out ..

    i did all this changes .. and i followed all the istructions , but i still have the same problem when i click to buy any new item from itune store .. etc
    i got a message " your apple ID has been disabled , please contact iTune support .
    hope to hear from you to sort out this issue as soon as possible .  thanks

    These are user-to-user forums, you can contact iTunes support here : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page

  • Airport Express issues sorted and itunes10 airplay working properly!!!

    I could not rename my original topic, but I have cut & paste the thread so all can read it, weeks of faffing about is now sorted!
    I have been running AX for almost 2 years with out an issue, that's with my router and AE in the living room, about 15 feet and a thin wall, could even join my laptop in my bedroom almost 60 feet away with out issues.
    My wireless internet connection keeps dropping out, I can wait for several minutes and it will re join automatically, if I go manual it asks for a password, even though it is saved in my keychain!
    I moved the router and AX next to my imac and the issues are still occurring.
    I am running 10.6.7, have all updates on AX. run 4GB ram, checked activity monitor, all good.
    I am not exactly computer savvy, but I was wondering as my router is a little older (Motorola SBV5121E Cable modem) could it be possible that it may not communicate with the AX since updates?
    I plugged ethernet directly into my imac from router and no problems what so ever.
    Is it possible to run my imac directly from the router and still set up a wireless network using my imac as the base station? This would then solve the issue as the wireless connection is really only needed for the wife and iphone surfing etc ??
    Or can I get a wireless router that enables my imac to plug into it directly and also create a wirless network for my AX's (hopefully x 2) to operate. Any recommendations as to the best wireless router?
    Any help greatly appreciated.
    imac Mac OS X (10.6.7)
    Reply from Tesserax
    Yes, you could use your iMac as a "software" router, sharing its wired Internet connection to wireless devices (like the iPhone) via its built in AirPort wireless. Apple calls this feature: Internet Sharing.
    Here are the basic steps to configure it:
    To setup for Internet Sharing (Wired to Wireless):
    Setup the Network
    Cable Modem > (Ethernet cable) > [Ethernet port] iMac > (wireless) > iPhone
    Enable Software Firewall - iMac
    System Preferences > Security > Firewall
    o Block all incoming connections (enabled)
    Enable Internet Sharing - iMac
    System Preferences > Sharing
    o Select "Internet Sharing" from the options in the left column
    o Share your connection from: Built-in Ethernet
    o To computers using: AirPort (checked) (Note: Uncheck all other entries in the list.)
    AirPort Options...
    o Network Name: <anything you want>
    o Channel: Automatic
    o Enable encryption (using WEP) (optional)
    o Password: (optional)
    o Confirm Password: (optional)
    o WEP Key Length: (optional)
    o Click OK
    o Select "Internet Sharing" again
    o Click "Start" to start Internet Sharing
    o Click Start
     Macmini3,1 Mac OS X (10.6.7)  Macmini1,1  MacBook4,1  PowerBook5,6  PowerMac3,5
    My Reply:
    Halleluja! Thanks for the reply, I will have a play tonight after dinner and see whether I can get the "internet sharing" up and running.
    Will post my results,
    Cheers.
    Bez
    imac Mac OS X (10.6.7)
    bezza911
    Good Morning Tesserax,
    that's fantastic, I now have internet sharing and everything is perfect. My next question is, can I now add my 2 x airport express onto the network to "extend wireless network", and especially have it next to my audio to plug the speakers in for airplay around the entire apartment?
    Thanks in advance,
    Bez
    OK,
    I just tried setting up my AX, reset the device, reconfigured to "join a wireless network", waited a few minutes and an error message came up on my screen saying try again. Tried a 2nd time, same problem. Turned airport off on my internet sharing imac, then suddenly the AX went green, set up the other AX and the same scenario. Been playing "airplay" through both AX for 30 mins and happy to report that I no longer have the "drop out" of music that has plagued my configuration for weeks!
    I think Tesserax has created a solution for the numerous issues with itunes 10, via the internet sharing proceedure.....
    Yaaaahooooo,
    Cheers Tesserax, you da man!

    I have a similar issue. Station has been working with no issues since I purchased in May 2014.  But since last Monday (12/29/14), it just does not connect to the internet at all.  I have it connected via LAN cable from my Comcast router.  Verified the conditions of the LAN cable and the output of the COMCAST router as I plugged to a network switch and works with no other issues.  The 5 GHz signal totally disappeared, and the 2.4 GHz is there but no internet connection.  I use terminal to ping the station and obtain a reply from the station and the router, but no luck obtaining internet via the Apple extreme which is connected to my VOIP phone, my Apple TV, and all my music in the cloud.  Right now had to configure everything to receive the signal from the COMCAST router.  No one at the Apple store knows about this equipment, just IPhone6 jockeys.

  • CompareTo and sorting problems.

    hi all,
    and thanks a lot for your help.
    I have created the following class which as you can see creates an object and can sort an array of such objects
    with respect to the deadline variable using the compareTo method.
    import java.util.Date;
    public class Task {
         Date deadline;
         long runtime;
         public int compareTo (Object obj){
         Date thatDate = ((Task)obj).deadline;
         Date thisDate = new Date(0);
         int k = thatDate.compareTo(thisDate);
         return k;
    I am trying to find a way of sorting the Task objects with respect to the runtime variable but I cannot.
    Can you please make a suggestion?
    Thanks in advance,
    Dennis

    Your compareTo won't work: it doesn't compare the deadlines of the two tasks, but rather the deadline of one task with the fixed Date 1. January 1970. Try this instead (in addition to the advice of the OP):
    public int compareTo(Object obj) {
      Date thatDate = ((Task)obj).deadline; // this will throw an exception if obj is not a Task
      return deadline.compareTo(thatDate.deadline);
      // or: return thatDate.deadline.compareTo(deadline);
    }Also, consider making instance variables private and accessible through accessor methods.

  • CompareTo and Sorting Arrays

    I am trying to sort an array of telephone directory information by last, first names, but am having trouble understanding how to use the compareTo method to do so. I thought I could use Arrays.sort, but this doesn't seem to work....any help would be appreciated.
    public static Person [] sort(Person [] people) {
    Person [] sorted = Arrays.sort(people);
    return (Person[])sorted.toArray(new Person[sorted.size()]);
    }/* end sort method */
    //From Person class
    public int compareTo(Object o) {
    Person p = (Person)o;
    int temp;
    if((temp=getLastName().compareTo(p.getLastName())) == 0)
    if((temp=getFirstName().compareTo(p.getFirstName())) == 0)
    //not sure what to do here
    return temp;
    }

    You want to return a negative or positive or zero integer if this item is less than, greater than, or the same as, the object passed as an argument, right? (Read the API.)
    You're trying to sort by last name first, and if they're the same, then the first name, right?
    So you're not really checking for zero, you're checking for non-zero.
    I'm assuming that first name and last name are given by strings, which implements Comparable. So you can do:
    public int compareTo(Object o) {
      Person p = (Person)o;
      int temp = getLastName().compareTo(p.getLastName());
      if (temp != 0)
        return temp;
      // implicit else here
      // MORE CODE GOES HERE
    }I'll let you do the "MORE CODE GOES HERE" as an exercise.
    BTW if you're implementing Comparable, you should probably be overriding equals() as well.

  • Video labeling issue sorta fixed in iTunes 7

    OK, I had the problem in iTunes 6 where when you changed the video type from "movie" to "TV Show" it would work in iTunes but not show up on my 5G iPod.
    With the new version of iTunes it works...most of the time. However, some video files still won't show up on the iPod unless they're labeled as a movie. I know it's not really that big a deal, but if anyone figures out what the secret is, please let me know

    I'm an idiot. I noticed there's a setting to not download videos that have been watched - so I set it to download all and all the videos show up now.
    Duhhhh....

  • How to sort out different issues on Satellite A505-S6973

    Can anyone tell me, if the warranty period on my laptop has not passed, can i return my laptop to toshiba and have all my issues sorted out. Would there be a cost to do whatever repairs software related needs be done and how i am supposed to go about it because my laptop is beginning to have all sorts of little errors, i noticed that my harddrive has 156gb used although i have about 60 gigs in use.
    A couple multimedia buttons aren't working but i touch them, my touchpad doesn't turn off with the hard button unless i turn it off using the FN key and my processor runs low but when i use a program i see it's reaching between 85 to 100% utilization.
    I really like this laptop, but the issues i'm having i highly doubt it should operate this way.

    Hi mate
    Software issues are not covered by warranty!
    This means that you will have to pay for everything if the ASP technician would not find any problems!
    This is why you should recover the notebook in order to check if its only a software related issue.
    >A couple multimedia buttons aren't working but i touch them, my touchpad doesn't turn off with the hard button unless i turn it off using the FN key
    Reinstall the VAP (value added package) and flash cards utility
    >my processor runs low but when i use a program i see it's reaching between 85 to 100% utilization.
    This is not a bug or hardware problem. You will notice this CPU behavior because the CPU supports an feature which helps to save the power and reduce the heat dissipation

  • Possible resolution to sorting issue in iTunes 9 and 3.1

    For those experiencing issues sorting Podcasts chronologically:
    One particular daily podcast I subscribe to was not sorting correctly (was in random order on the iPod Touch 32gb 2nd Gen).
    I did notice the "Release Date" wasn't carrying over to the iPod during the syncing process.
    (If you try this, copy any podcasts you can't afford to lose to a separate directory)
    1) I unsubscribed from the podcast in iTunes 9
    2) deleted all the episodes from iTunes
    3) Synced iTunes / iPod - (basically removing remnants of the podcast)
    4) Went back to the iTunes store and subscribed again to said podcast
    5) "Get" the episodes I wanted
    6) Synced iTunes and iTouch
    Thankfully, this corrected the issue of random sort order on my iPod - now the "Release Date" is again noted / visible when looking in the iPod and it is ordered correctly.
    Hope this provides some relief to some.

    I had this happen with my 3GS almost a month ago. No amount of trying to restore would work and the Apple Genius claimed he had never seen anything like it.
    My iPhone was bricked with the error 23. I plugged it into XCode and it failed to restore saying there was a radio failure. There was no 3G, no WiFi no edge and no bluetooth. They were all grayed out in settings. Apple replaced my phone with no problem. This is what you will end up having to do as well.
    You will be able to restore from your previous backup.

  • Smart playlist sort order issue

    I'm having an issue sorting a smart playlist. I've searched through other questions on here but can't find the identical issue.
    I've created a smart playlist that contains the contents of two other smart playlists. I've tried to sort this list by 'name', by clicking on the arrow in the column heading, but the list still leaves the two playlists separately, ie. it sorts each original playlist separately, and then puts one after the other in the play order.
    I have other smart playlists constucted in the same way, and have no issues with them, and I can't see what the difference is with this one!
    I'm using 11.0.4.4, on a Windows 7 PC.

    I am also having the same problem. Running the newest iTunes and iPhone software my smart playlists are not working correctly. My "Recently Added" is correct in iTunes, and if I look at the playlist on my iPhone info in iTunes it is correct there, but the actual playlist on my iPhone is populated entirely with audiobook files. I have tried deleting and recreating the playlist which gives the same results. I have also specified that items within the playlist should be music files only and still get the same results.
    I have a playlist that's Top 50 Most Played that's also not behaving properly (ie correct in iTunes but not on my iPhone).
    Any suggestions?

  • Sorting issue on - around 20 records based on one field Data Manager

    Hello Experts,
    We are facing issue sorting some records which belong to one contract.
    if we sort by one field ie item no, it is not sorting based on this field. This issue only one set of contract only.
    For other set of data, sorting is working fine.
    Any hint will be appreciated.
    Thanks in advance

    HI saptest,
    I have not heard of such a issue,please provide detailed description of the same to give a better idea.
    Thanks,
    Ravi

  • How can I do sorting from ascending to descending then unsort?

    Hi all,
    Can anybody help on this issue?
    I have a bunch of numbers in a table, and I hope when I click the column header once, it will do ascending.
    Click again, do descending. Then click three times, become unsort (which is origially ordered in absolute value).
    I tried to add tree SortKeys in sorter, but it doesn't work:
    List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
    sortKeys.add(new RowSorter.SortKey(2, SortOrder.UNSORTED));      // 2 means it's the 3rd column I want to sort
    sortKeys.add(new RowSorter.SortKey(2, SortOrder.DESCENDING));
    sortKeys.add(new RowSorter.SortKey(2, SortOrder.ASCENDING));
    sorter.setSortKeys(sortKeys);Then I tried to implement my own Comparator, but will always get numbers ordered in absolute value.
            Comparator<Float> comparator = new Comparator<Float>() {
                public int compare(Float s1, Float s2) {
                    if (s1 < 0) s1 *= (-1);
                    if (s2 < 0) s2 *= (-1);
                    return s1.compareTo(s2);   
            sorter.setComparator(2, comparator);      // 2 means it's the 3rd column I want to sortThank you very much indeed in advance.
    Cheers,
    George

    Apologies for not saying it clearly.
    I can easily do ascending and decending by applying this:
            sorter = new TableRowSorter<TableModel>(table.getModel());
            table.setRowSorter(sorter);But I also need my data to be sorted by absolute value. That's why I tried to implement my own Comparator.
    However, it turned out that I will only have one sorting method, which is the absolute value as you have noticed.
    Hence I hope the result, if possible, would be if I first click the column header, ascending orders.
    Click the second time, decending orders. And then click the third time, absolute value orders.
    Cheers

  • TS1398 Got the dreaded no wifi on my wife's iPhone 4S. Wifi greyed out and no luck with the reset network instructions. Why isn't Apple addressing this issue? We are a family of Apple product users, 2 ipads, an ipad mini, 4 iPhones but one isn't working!

    Got the dreaded no wifi on my wife's iPhone 4S. Wifi greyed out and no luck with the reset network instructions. Why isn't Apple addressing this issue? We are a family of Apple product users, 2 ipads, an ipad mini, 4 iPhones but one isn't working! Issue began whenwe upgraded the operating system.....
    Come on Apple.....get this issue sorted out!

    Just out of warranty. This is a software issue. everything was ok until the software update. Apple just need to sort it out.

Maybe you are looking for

  • Adobe 9.1 error 0x20c

    Hi everyone! I got a problem when signing PDF files. I wrote a piece of code that performs the signing, and until recently all worked fine! Then, I switched to Reader 9.1, and now some of my signed documents are not validated: an inner ciphering libr

  • Ipad mini constantly restart by its own

    The screen suddenly displays some black strip then shut down and restart, happens often with some tap and sometimes on its own. The issue starts to constantly happen ever since one time when the device shut down by out of battery. Any help to resolve

  • End All Kernel Panic Troubleshooting List

    I have been tasked to put together an end all list to troubleshooting Kernel Panics. Please take a look at this list to verify if I missed any steps you would try. I understand that there will be specific fixes to specific causes, and not all of thes

  • Sybase Input Parameter ?

    folks i am trying to execute a sybase stored procedure it expects one input parameter , below is the stored procedure name and the input parameter, sp_case '@sCase_ID' From my program if i pass in <b>Case_ID</b> to this stored procedure , It's compla

  • Set time automatically suddenly 5h 56min slow

    This is bizarre and AT&T was not able to help. Two days when traveling by car from Minneapolis to Fargo (same time zones) my iPhone 4 phone suddenly began to display a time that was 5 hours and 54 minutes in the past. What is strange is that one of m