Results 1 to 3 of 3
- 10-10-2011, 07:43 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 16
- Rep Power
- 0
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.
- 10-10-2011, 08:36 PM #2
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
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.
- 10-10-2011, 08:49 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 16
- Rep Power
- 0
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
-
implementing a sorting feature
By -Dman100- in forum New To JavaReplies: 8Last Post: 01-12-2011, 07:08 PM -
Arrays vs LinkedList When Implementing Stacks
By Lil_Aziz1 in forum New To JavaReplies: 7Last Post: 06-23-2010, 08:47 PM -
Help with sorting arrays
By Joycey in forum New To JavaReplies: 4Last Post: 03-30-2010, 08:35 PM -
Arrays.sort... why sorting all arrays in class?
By innspiron in forum New To JavaReplies: 6Last Post: 03-23-2010, 01:40 AM -
Sorting Two Arrays
By Faye Rett in forum New To JavaReplies: 4Last Post: 03-07-2010, 01:00 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks