Results 1 to 3 of 3
  1. #1
    jakaldama is offline Member
    Join Date
    Sep 2011
    Posts
    16
    Rep Power
    0

    Default Implementing Sorting in Arrays Question

    I am attempting to sort a number of Sales Persons' sales in an array. I first made a SalesPerson class that get name and sales #'s.

    I then made another class named ArraySorter that should hopefully take the sales numbers and sort them in order.

    I finally have the SalesReporter class file that consists of getData (enter in the number of sales people that will be used, the names and sales #'s)

    I then need a section dealing with taking those numbers and implementing the arraySorter I have, I believe. I am taking bits and pieces of reading and examples from my textbook, which in a previous part may have created something like computeData (to get the average of the sales or something easier).

    Then display results, and the main method which my thoughts are going towards:

    SalesReporter clerk = new SalesReporter();
    clerk.getData();
    clerk.??? --this could have been computeData(); but I have a separate array-sorting class.
    clerk.displayResults();


    Am i looking at this the wrong way? I suppose I'm not understanding how to use my array sorter in this case.

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Implementing Sorting in Arrays Question

    Without knowing how your array-sorting class works, it's hard to say.

    You might be interested in the Arrays class though.

  3. #3
    jakaldama is offline Member
    Join Date
    Sep 2011
    Posts
    16
    Rep Power
    0

    Default Re: Implementing Sorting in Arrays Question

    My Array sorting class is as follows:


    public class ArraySorter
    {
    //every element in SalesAssociate has a value

    public static void selectionSort(int[] sales)
    {
    for (int index = 0; index < sales.length - 1; index++)
    {
    int indexOfNextSmallest = getIndexOfSmallest(index, sales);
    interchange(index, indexOfNextSmallest, sales);
    }
    }
    private static int getIndexOfSmallest(int startIndex, int[] a)
    {
    int min = a[startIndex];
    int indexOfMin = startIndex;
    for (int index = startIndex + 1; index < a.length; index++)
    {
    if (a[index] < min)
    {
    min = a[index];
    indexOfMin = index;
    }
    }
    return indexOfMin;
    }

    private static void interchange(int i, int j, int[] a)
    {
    int temp = a[i];
    a[i] = a[j];
    a[j] = temp;
    }

    }

Similar Threads

  1. implementing a sorting feature
    By -Dman100- in forum New To Java
    Replies: 8
    Last Post: 01-12-2011, 07:08 PM
  2. Arrays vs LinkedList When Implementing Stacks
    By Lil_Aziz1 in forum New To Java
    Replies: 7
    Last Post: 06-23-2010, 08:47 PM
  3. Help with sorting arrays
    By Joycey in forum New To Java
    Replies: 4
    Last Post: 03-30-2010, 08:35 PM
  4. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  5. Sorting Two Arrays
    By Faye Rett in forum New To Java
    Replies: 4
    Last Post: 03-07-2010, 01:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •