COSC4301			Program-2			Due:  9/20/2012
			Class Design and Sorting
Objectives:

1. Design of a new class with multiple methods including a constructor.
2. Sorting one-dimensional array of random integers, SelectSorting and QuickSorting.
3. Printing out integers right-justified.

Tasks:
1. Complete the following six methods:
	selectSort()
	quickSort()
	calMax()
	calMin()
	getMax()
	getMin()
2. Create an object of IntegerArray whose elements are random integers 
   between 1 to 9999. These random numbers will be the contents of the instance 
   variable original of this object of this class.
3. Print out result of selectsorting the object of above step (2) with a suitable heading.
   Output integers should be all right-aligned.
4. Create another object of this same class such that the contents of the same instance 
   variable, original, will be random integers between 10000 and 20000 inclusive.
5. Print out the results of quicksorting the second object of step (4) above with 
   a suitable heading with output integers right-justified.
6. Print out the Max and Min of the second object.
/*  ********************************************************************
Example of a new class IntegerArray.
Instance Variables:
  MAX:      final static int MAX=100;
  original: int[MAX];
  sorted:   int [MAX];
  sum:      int;
  max:      int;
  min:      int;
public methods:
  bubblesort();
  quicksort();
  selectsort();							
  calSum();
  calMax();
  calMin();
  getSum();
  getMax();
  getMin();
  display();	// display sorted result
//********************************************************************
*/
import java.util.Random;

public class IntegerArray
{	final static int MAX=100;
        private int[] original = new int[MAX];
        public  int[] sorted =   new int[MAX];
	private int sum, max, min;
// Constructor will set the original array by generating random
// integers determined by the given parameter
	public IntegerArray (int upper) 
        {       Random generator = new Random();
                for (int index=0; index <= MAX-1; index++)
                original[index] = generator.nextInt(upper)+1;  
	      // generated integers are between 1 and upper.
	}
//////////////////////////////////////////////////////////////////
	public void bubblesort ()
	{	// first copy original to sorted so as to sort sorted 
		// thereby leaving original intact
		for (int index=0; index <= MAX-1; index++)
			sorted [index] = original [index];
		// now sort the copied sorted array.
		for (int last=MAX-1; last>=1; last--)
		  for (int first=0; first<=last-1; first++)
			if (sorted[first]>sorted[first+1]) // Swap them.
			{	int temp =sorted[first];
				sorted[first] = sorted[first+1];
				sorted[first+1] = temp;
			}
	}	//  end of bubblesort()
////////////////////////////////////////////////////
        public void display()   // Displays sorted array
	{	for(int index=0; index <= MAX-1; index++)
                {       System.out.printf ("%8d", sorted[index]);
			if ((index+1)%8 == 0)
			  System.out.println();
		}
	}
	public void calSum()
//    calculates the sum of all integers in the array and sets instance
// 	variable sum to this calculated total.
	{	int total = 0;
		for (int index=0; index <= MAX-1; index++)
			total += original[index];
		sum=total;

	}
//////////////////////////////////////////////////////////////////
	public int getSum()
        { return sum;
        }
/*	You are supposed to complete the rest of this class and the whole 
	program
*/
	public static void main (String[] arg)
	{	IntegerArray xint = new IntegerArray(1000);
		IntegerArray yint = new IntegerArray(10000);
		xint.bubblesort();
           xint.calSum();
		int total = xint.getSum();
		xint.display();
                System.out.println ("\nTOTAL OF ALL ARRAY ELEMENTS::: " + total);
                System.out.println();
	}
 }	//End of program to modify