Since this is a re-attack on my first question, I will begin by restating that I am a java newbie. I am also trying to work through a college level java assignment for this week. To caveat this, let me say I barely know what I am doing. The assignment this week after getting clarification; is simply this:
You need to write an actual ClassClient for this project that:
- declared and initializes your data array
- creates a SortingClass object,
- prints the array of data (unsorted)
- sends the array into the SortingClass's constructor (which sorts the contents of the array)
- prints the same array of data (now sorted)
As of now, I am working through it set step by step. Currently, the only error NetBeans is giving me is that in my second class, everywhere array1 is used is underlined and I assume it means they are not linking to the first class where the array list is placed. MY first question is, I'm obviously not linking correctly; what am I missing? I am also using the selection sort method.
My first class called ClientClass
public class ClientClass {
public static void main( double [] array ) {
double array1[] =
{53.5, 60.3, 96.2, 53.3, 56.4, 52.7, 76.4, 77.5, 71.0, 78.2,
65.2, 59.3, 80.5, 92.1, 85.7, 78.7, 66.2, 88.8, 50.2, 73.4};
//Create a SortingClass variable with data gievn in the array
SortingClass g = new SortingClass();
// Print array unsorted
for (double number : array1)
{
System.out.println("Number = " + number);
}
String outPutString = g.toString();
System.out.println(outPutString);
}
}
and I have written the second class
public class SortingClass {
// Selection Sort
public static void ClientClass (double [] array )
{
double temp;
int max;
// Selection Sort Method
for (int i = 0; i < array1.length - 1; i ++)
{
max = indexOfLargestElement ( array1, array1.length - i );
temp = array1[max];
array1[max] = array1[array1.length - i - 1];
array1[array1.length - i - 1] = temp;
}
}
public static int indexOfLargestElement ( double[] array1, int size)
{
int index = 0;
for ( int i = 1; i < size; i++ )
{
if ( array1[i] > array1[index] )
index = i;
}
return index;
}
}