Help needed badly for selection sort

I posted this on the other forum but haven't gotten a reply. I have a class that compares the zip codes of a file that is read into the code and store as objects. Now I have to sort the information by the zip codes this is what I have so far and I do not know what I am doing wrong with the selection sort. This is the first time I am doing selection sort.
Here is my .txt
10
Dillin Jake York PA 17409
Valdir John Chicago IL 98098
Morphy Bob Harrisburg PA 73829
Spears Johnathan Chicago IL 09182
Simpson Bloo Los Angeles CA 94840
Griffin Taylor York IL 49283
Cartmen Eric Philadelphia PA 28192
Connaly Teds Springfield IL 12930
Marsh Stan Miami FL 48392
William Thomas Reno NV 39029
and this is the code:
import java.util.*;
import java.io.*;
import java.util.Scanner.*;
public class TestCustomer6 {
  public static void main (String[] args) throws FileNotFoundException {
    Scanner scan = new Scanner (new File ("customerData.txt"));
    int numLines = scan.nextInt();
       Customer2[] customer;
     customer = new Customer2[40];
    for (int i = 0; i < numLines; i++) {
      String fName = scan.next();
      String lName = scan.next();
      String city = scan.next();
      String state = scan.next();
      int zip= scan.nextInt();
     Customer2 newObj = new Customer2(fName,lName,city,state,zip);
    customer=newObj;
public static void selectionSort(int[] array)
{int count;
   for (count = 0; count < array.length; count++)
      int indexOfMin = findMinimum (array, count);
       swap (array, count, indexOfMin );
     public static int findMinimum (int[] array, int startIndex)
{int mycount;
     int indexOfMin = startIndex;
       for(mycount = startIndex + 1; mycount < array.length; mycount++)
          if (array[mycount] < array[indexOfMin]
indexOfMin = mycount;
return indexOfMin;
     public static void swap (int[] array, int preIndex, int nexIndex)
double temp = array[preIndex];
array[nexIndex] = array[preIndex];
array[nexIndex] = temp;
the class:
import javax.swing.*;
class Customer2{
    public static final int FNAME = 0;
    public static final int ZIP = 1;
    private static final int LESS = -1;
    private static final int EQUAL = 0;
    private static final int MORE  = 1;
    private static int compareAttribute;
     private String firstName;
     private String lastName;
     private String city;
     private String state;
     private int zip;
    static {
       compareAttribute = FNAME;
     public Customer2(){
     firstName = " ";
     lastName = " ";
     city = " ";
     state = " ";
     zip = 0;
     public Customer2(String f, String l, String c, String s, int z){
          this.firstName = f;
          this.lastName = l;
          this.city = c;
          this.state = s;
          this.zip = z;
          System.out.println(this.toString());
    public static void setCompareAttribute( int attribute ) {
        compareAttribute = attribute;
    public int compareTo( Customer customer, int attribute ) {
        int comparisonResult;
        if ( attribute == ZIP ) {
            int p2zip = customer.getZip( );
            if (this.zip < p2zip) {
                comparisonResult = LESS;
            } else if (this.zip == p2zip) {
                comparisonResult = EQUAL;
            } else {
                assert this.zip > p2zip;
                comparisonResult = MORE;
        } else { //compare the name using the String class�s
                //compareTo method
            String    p2fname = customer.getFirst( );
            comparisonResult = this.firstName.compareTo(p2fname);
        return comparisonResult;
    public int compareTo( Customer customer ) {
        return compareTo(customer, compareAttribute);
     public String getFirst(){
          return firstName;
     public String getLast(){
          return lastName;
     public String getCity(){
          return city;
     public String getState(){
          return state;
     public int getZip(){
          return zip;
     public String toString(){
          return  getFirst() + ",  " + getLast() + "     " + getCity() + "     "
          + getState() + "     " + getZip();

1) Your code doesn't compile;
2) You don't call your selection sort method anywhere;
3) Your selection sort attempts to sort an int array which doesn't make sense;
4) You don't use the comparison methods defined in your Customer2 class;
5) I think that you've just copied/pasted several code fragments;
6) Your indentation style is highly inconsistent (also see 5).
kind regards,
Jos

Similar Messages

  • Help needed badly for AFMLE

    Okay so here's what's going on. I'm trying to start up a livestream to own3d.com playing league of legends but I've got a serious problem. When I use VhScrCap and FME to the stream, the output is all wrong. I don't know how to describe it so i've decided to make a video showing the problem. Basically when I use VhScrCap it doesn't get the whole screen in FME but if I use, say, SCFH DSF instead, it fills the whole FME screen (but with a MUCH lower quality) difference between 720p and 240p. Here's the video showing my problem.
    http://www.youtube.com/watch?v=922ECExhsJ4
    EDIT: 1080p version: http://www.youtube.com/watch?v=WPaYTtJBteo
    The video really isn't that clear but I think you'll get the jist of what I mean.
    Thanks,
    Kyle

    1) Your code doesn't compile;
    2) You don't call your selection sort method anywhere;
    3) Your selection sort attempts to sort an int array which doesn't make sense;
    4) You don't use the comparison methods defined in your Customer2 class;
    5) I think that you've just copied/pasted several code fragments;
    6) Your indentation style is highly inconsistent (also see 5).
    kind regards,
    Jos

  • How to assign search help using ovs for select options for ALV in web dynpr

    how to assign search help using ovs for select options for ALV in web dynpro

    Hi,
    refer http://wiki.sdn.sap.com/wiki/display/WDABAP/InputhelpofObjectValueSelectioninWDABAP
    http://www.****************/Tutorials/WebDynproABAP/OVS/page1.htm
    and http://wiki.sdn.sap.com/wiki/display/Snippets/WebDynproAbap-OVSsearch+help
    Thanks,
    Chandra

  • Help need driver for Mac Yosemite 10.10.2 for LaserJet Pro Color...

      Please help me find the driver for the HP LaserJET COLOR PRO 200 FOR MAC OXC 10.10 YOSEMITE
    This question was solved.
    View Solution.

    This should be what you need
    Driver for for OS X 10.9 Mavericks and OS X 10.10 Yosemite
    http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=lj-125410-4&cc=us&dlc=en&lc=en...
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • Need BADI for PV34

    Hi,
    I am working on HR ESS and i need a BADI for tcode pv34 to restrict the user to make his own appraisal not the others.
    And the main thing is it shud be only ESS side the check shud not be  there at R/3 side . We are using R/3 Iview on ESS side.
    Waiting for ur reply.....
    Thanks &Regards,
    Srinath

    Hi
    check this:
    [http://wiki.sdn.sap.com/wiki/display/ABAP/FindaBADI]
    Regards
    Markus

  • I need Badi for PO Before save.

    Hi Abappers,
    i want Badi name for PO Before save.
    Regards,
    vani.

    Hi,
    To find the badi for a particular transaction goto TCode SE24 and give the class name as CL_EXITHANDLER and then display it. now double-click on GET_INSTANCE you will get some source code , put a break point on class name and give TCode on command field then debug . double click on class name and go on pressing F5, you willl get list of BADI's and according to your requirement choose the right one.
    Second procedure:
    Go to SE84, Enhancements< Business-addin< definition(double click) and give package name of particular transaction then you will get BADI's. Read documentation by going to SE18 or SPRO and choose the right one according to your requirement
    I think ME_PROCESS_PO_CUST may satify your requirement.

  • Sorting Issue Help Needed Badly

    *+{color:#000000}*Hello All,*+*
    I am having a small piece of code in my project that retrieves file names from a directory applying filename filter. Well i am happening to get them fine in sorted order. But when i implement that program in other machine it happens that all the file names are in unsorted order. I applied several sorting techniques Collator, SortedSet etc. no luck+</stro
    Any could help me on this. By the way my development machine has JDK 1.6 while implementing system has only JRE1.5 which comes embedded with jBase. Consider i have nothing to do with jBase thats another team's project.{color}+*
    FilenameFilter fileNameFilter = new SEPITFilenameFilter(".JPG");
    String slideURLs[] = slideBase.list(fileNameFilter);
    slideURLs = Storage.sortStringsInAscending(slideURLs);
    public static String[] sortStringsInAscending(String[] array)
    Collator collator = Collator.getInstance();
    CollationKey collationKey[] = new CollationKey[array.length];
    for(int k=0; k<array.length; k++)
    collationKey[k] = collator.getCollationKey(array[k].trim());
    int i=0;
    boolean swapped = true;
    while(swapped)
    swapped = false;
    i++;
    for(int j=0;j<(array.length-i);j++)
    int comparator = collationKey[j].compareTo(collationKey[j+1]);
    if(comparator > 0)
    String tempString = array[j];
    array[j] = array[j+1];
    array[j+1] = tempString;
    swapped = true;
    return array;
    }

    Well, if you simply want to sort the file names themselves, build a List and then call Collections.sort(). String already has a comparator built-in that will sort them ascending for you.
    If you want to customize things, write a Comparator. Then call Collections.sort().
    - Saish

  • Need help with SQL for selecting ID where the sequence does not match..

    I have the following dilemma:
    Database contains IDs as follows:
    Incident#, Case#, & Part Sequence#
    example
    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1
    Record 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 2
    Sometimes the user will delete (let's say) Record 2 after creating a new Record 3
    So now the sequencing goes as follows:
    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1
    Record 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 3
    Now there will no longer be a Part_Sequence 2
    Need a SQL to select all records where the maximum part sequence > than the count of Incident_number||'-'||Case_number
    I tried the following:
    select a.incident_number||'-'||a.case_number||'-'||a.part_sequence
    from chsuser.a_compl_summary a
    where a.entry_date >= '01-may-2011'
    and max(a.part_sequence) > count(distinct a.incident_number||'-'||a.case_number)I end up getting a ORA-00934: group function is not allowed here (highlighting on the Max(a.part_sequence) portion.
    Any suggestions/hints
    Thanks

    select  incident_number || '-' || case_number || '-' || part_sequence
      from  (
             select  incident_number,
                     case_number,
                     part_sequence,
                     max(part_sequence) over(partition by incident_number,case_number) max_seq,
                     count(*) over(partition by incident_number,case_number) cnt
               from  chsuser.a_compl_summary
               where entry_date >= DATE '2011-05-01'
      where cnt != max_seq
    /SY.

  • Urgent Help needed - BADI's in Infospoke

    Hi,
    My Scenario:
    I am pulling data from master data using infospoke into Application server. I need some kind of easy transformations during this stage.
    I got ZSTATE field in my data and I need to restrict my output to only certain states(Ex: NJ,CA, TX , MNetc). Since I can't give those selection conditions in infospoke I need to try BADI. I created a BADI and have target and source structure. Can anyone write me small code for this to eliminate other states and allow NJ , CA, MN, TX etc.
    Source structure: /BIC/CYZZTEST
    target Structure: /BIC/CZZZTEST
    infospoke: ZZTEST
    Field: Zstate
    Class:ZCL_IM_ZZTEST
    Method:IF_EX_OPENHUB_TRANSFORM~TRANSFORM
    Full points to helpful answer!!
    Anil.

    The problem is cross user too - I have two user files on the machine and the same thing happens regardless of which user file I'm working in.
    That points to s 'system-wide' issue.
    Try resetting your SMC.
    Resetting the System Management Controller >>
    Also, you could try booting from your install DVD and see if it does it there. If it does not, it's more than likely a software issue and an Archive and Install should fix it.
    Mac OS X: About the Archive and Install feature >>
    -Bmer
    Mac Owners Support Group - Join us @ MacOSG.com
      Mac611 Mobile Mac Support - about.Mac611.com
       iTunes:MacOSG Podcast | YouTube.MacOSG.com
                       An Apple User Group 
    Have an iPhone or iPod touch? Enter Mac611.com in Safari on it for 'mobile Mac support.'

  • Help Needed in At selection screen output

    Hi Experts,
    I need your help in AT SELECTION SCREEN OUTPUT event. My issue is i have 4 radio button and with each radio button couple of parameters that need to be filled in selection screen of report. My requirement is that sometimes user enters details in second radio button parameters but forgot to change the radio button to second one so kindly suggest a solution so that radio button gets selected as per user input in parameter like if user clicks on certain parameter to enter value then automatically corresponding radio button gets selected.
    Thanks in advance for all your help.

    example from a checkbox in one of my progs..but you can do same approach with radio butts
    parameters p_test as checkbox default abap_on user-command test.
    at selection-screen.
        if sy-ucomm = 'TEST'.
          perform birth_mnth_chck.
        endif.

  • Help needed in row selection in Tabular form across pages

    Hi,
    I have a tabular form report similar to http://htmldb.oracle.com/pls/otn/f?p=31517:95. I want to select some rows from first page and then use the pagination to get to the next page, select some more rows and hit the submit button for processing. The rows selected in the last page alone are picked up for processing, and the ones selected in the earlier pages are lost. I see the same behaviour in Denes' example as well. I picked a row in the first page and a row in the next page, and then click "Pick Records", i see only the record i picked on the second page.
    I did play around with "partial page refresh" setting for the tabular form region, but that does not help.
    Is there a way to select across pages in a tabular form?
    thanks,
    Rams
    Edited by: rams1234 on Jan 22, 2009 10:19 AM

    Okay. I could make this work, but this seems to be a roundabout way for me. In my case I dont have any database related query to get the values, hence the Application level process may not be needed.
    When I select the checkbox, i get the value. I am hoping that I should be able to send the value to a javascript function and update the filed value in the function itself. Please see the function below..
    function setFileID(pThis) {
    var chkvals=pThis.value;
    var fldValue = new $x('f_FILELIST').value ;
    if (fldValue != 0)
    { $x('f_FILELIST').value= fldValue+'-'+chkvals;}
    else
    { $x('f_FILELIST').value = chkvals ;}
    This function works fine in making up the list. The issue is, when an already selected row is unselected, the value of the checkbox gets added one more time :) If I detect the checkbox status and subtract the corresponding value, this will be perfect..
    Thanks for the link anyway. I am marking this question answered.
    regards,
    Rams.
    Edited by: rams1234 on Jan 22, 2009 1:18 PM

  • Menu Button not working at all..Please help needed urgently for deadline.

    I have used all the suggestions I can find in the forum. Nothing is working.
    I am trying to draw button rectangle on a still background for a menu. Draging the pointer doesn't do anything. I have tried to import a tutorial with menu and buttons within it. When loading the project assets the import stops at "Loading menu" and does not proceed.
    I am using suitcase fusion for a font manager.I have reinstalled the DSP a few times without any success.
    I have spent three nights trying to solvge the problem and I am running out of time for the project delivery help is need urgently

    Your key is the "suitcase fusion for a font manager" line.
    There is a bug where you won't be able to create a button if you have a bad font, or a duplicate font, installed.
    First try shutting off all of the fonts you have open with Suitcase, and see if that helps. If so, open one suitcase at a time until you figure out which font is the culprit.
    If shutting off all but the basic System fonts does not help, you might have to reinstall your system, or somehow update your core System fonts. I don't know how to do that, but there was a recent article at http://www.tidbits.com/ that discussed fonts and their maintenance. But ultimately it's a font problem.

  • Need BADI for MRI7 Tcode.

    Hi,
    Please help me in getting BADI or Screen Exit for MIR7 Tcode where in I need to add new field at Item level.
    Thanx for your help.

    Hi,
    Check from the following
    Exits:
    MRMH0001                                Logistics Invoice Verification: ERS procedure
    MRMH0002                                Logistics Invoice Verification: EDI inbound
    MRMH0003                                Logistics Invoice Verification: Revaluation/RAP
    MRMN0001                                Message output and creation: Logistics Invoice Verifica
    LMR1M001                                User exits in Logistics Invoice Verification
    LMR1M002                                Account grouping for GR/IR account maintenance
    LMR1M003                                Number assignment in Logistics Invoice Verification
    LMR1M004                                Logistics Invoice Verification: item text for follow-on
    LMR1M005                                Logistics Inv. Verification: Release Parked Doc. for Po
    LMR1M006                                Logistics Invoice Verification: Process XML Invoice
    Business Add-in
    INVOICE_UPDATE                          Business Add-In: Logistics Invoice Verification
    Regards,
    Surinder

  • Eclipse error | Help needed badly

    Hi,
    My Eclipse was working properly a couple of days back but suddenly It's stopped working and gives me an error : "workspace does not contain a main type,Do you have a public void run method"
    Now,I think the problem Is some how the jar's that I'm trying to upload aren't getting uploaded.
    I say this because a strange problem has arised and I think this might have to do with Eclipse giving the above error.
    This Is what I do to create a new java project
    -Open eclipse
    -save files to workspace
    -click on new > java project
    -Then,give the project a name and then click finish
    -after that I create a new class by right clicking on the project folder > new > class >give the class a name and then click finish.
    -after that I open workspace(thats on my desktop) click on the project folder make a new folder name It "lib" and upload the jar that I need for the project.
    -after this I go back Into eclipse and right click on the project folder and hit refresh,now I see the folder"lib" containing the jar Inside It.
    -I right click on the jar file and select "add to build path",and now theres the Issue comes In.
    I want the jar to Into the reference librarys,because the last time I got the jar In the reference library It worked.
    But this time I can't even manage to find where the reference library Is.
    so when I click on add to build path the jar Instead of appearing in the reference library (which Isn't there) just dissapears.
    I really need to fix this,because I cant test and write code until Its fixed.
    heres a snapshot of how my eclipse framework looks : [http://www.flickr.com/photos/38561743@N03/4122304046/sizes/o/]
    I tried to solve this on my own for hours and hours but It just Isn't working.
    please guys help,I need to solve this.
    Thanks,
    Edited by: Parastar on Nov 21, 2009 7:26 AM
    Edited by: Parastar on Nov 21, 2009 7:27 AM

    Parastar wrote:
    okay guys,I'v tried the eclipse forums for about 24 hours now.
    but no response,those guys are really really slow.
    please,some one here help me out.Quit begging. You've already been told this is not the place for this question. You're complaining about not getting an answer there, and begging people here to answer, as if that vindicates your decision to post here in the first place. But you haven't gotten your solution here either. Which is worse--no answer there, or a bunch of answers that don't help you here?

  • Help with timeout for select inside loop

    Hi everyone, im a little confused with this code. Can you help me to optimize it? Its giving Timeout dump.
    Thanks so much, I´m new in abap and I tried hard, but its getting worse.
    Any idea is welcomed.
    LOOP AT it_lips.
        SELECT SINGLE *
          FROM vbak
         WHERE vbeln = it_lips-vgbel.
        IF sy-subrc <> 0 OR vbak-vbtyp <> 'C'.
          CONTINUE.
        ENDIF.
        SELECT SINGLE *
          FROM vbup
         WHERE vbeln = it_lips-vgbel
           AND posnr = it_lips-vgpos.
        IF sy-subrc = 0 AND vbup-lfgsa = 'C'.
          READ TABLE it_likp WITH KEY vbeln = it_lips-vbeln.
          IF it_likp-wadat < it_likp-wadat_ist.
            it_data-statu = 'N'.
            v_countn = v_countn + 1.
          ELSE.
            it_data-statu = 'S'.
            v_counts = v_counts + 1.
          ENDIF.
        ELSE.
          CONTINUE.
        ENDIF.
        it_data-vbeln = it_lips-vgbel.
        it_data-posnr = it_lips-vgpos.
        SELECT SINGLE matnr arktx kwmeng vrkme
          INTO (it_data-matnr, it_data-arktx, it_data-mengs, it_data-vrkme)
          FROM vbap
         WHERE vbeln = it_lips-vgbel
           AND posnr = it_lips-vgpos.
        it_data-menge = it_data-mengs.
        it_data-kunnr = vbak-kunnr.
        SELECT SINGLE name1
          INTO it_data-name1
          FROM kna1
         WHERE kunnr = it_data-kunnr.
        it_data-edatu = it_likp-wadat.
        it_data-wadat = it_likp-wadat_ist.
        it_data-vkorg = it_likp-vkorg.
        APPEND it_data.
        CLEAR: it_data, vbak, it_vbep, vbap, kna1, it_lips, it_likp.
      ENDLOOP.

    The issue of SELECTing within a LOOP is much overblown. All of the SELECTs are SELECT SINGLE using the fully qualified primary key. Using a JOIN or FOR ALL ENTRIES might speed this up a bit, but dollars to doughnuts, the problem is here:
    READ TABLE it_likp WITH KEY vbeln = it_lips-vbeln.
    If it_likp is a standard table, you will be reading half of all of the entries, on average, every time you do the read. If you don't want to change it to a sorted or hashed table, SORT it_likp by vbeln before going into the loop and use the addition BINARY SEARCH on the READ statement.
    Rob
    Edited by: Rob Burbank on Apr 18, 2010 9:34 PM
    Edited by: Rob Burbank on Apr 19, 2010 10:15 AM

Maybe you are looking for

  • Is it  possible to upload few column in table through  Apex Data Loading

    Hi All, I have to do upload into the table through a csv file . The table's primary key i have to load the rest through user's uploaded file. Is it possible to do the data loading to the table only to required columns and fill the other columns from

  • Trying to convert word to pdf and getting error message using Ver. 7

    I what sent a word doc by a correspondent of mine which I tried to convert to a pdf. I right clicked the doc on my desk top and chose "convert to PDF". It looked as it has all the other times but after it had opened word it came up with an error wind

  • Auto Apply Custom Color Palette to photo?

    I have two questions: 1) Is there a way to automatically capture colors from a photo to automatically create a custom color palette? (for example, if I want a color palette of 20 colors, it would automatically pick 20 colors and create a palette). 2)

  • How to implement auto increment in jpa

    Hi all how can we indicate that the strategy for primary key generation in auto increment?( the database is mysql5) thanks for help

  • Photoshop CS5 Crash on opening/creating Image

    -Just updated -Went to open an image, crashed -Went to make a new image, crashed -Any image i make/open crashes Adobe CS5 (Any setting) -Didn't have the problem ever befor +The pictures above tell the issue in a nut shell