/** A NumberArray used to manage integers. */
public class NumberArray {
  private int[] numbers; // instance variable single dimension array of ints
  
  /** Construct a NumberArray.  Prompt the user for the size of the array,
   *  create the array numbers using the given size, then prompt for
   *  the individual values and populate numbers.
   */
  public NumberArray() {
    int size;
    do {
      System.out.print("How many numbers in the array? ");
      size = In.getInt();
      if (size >= 0) {
        numbers = new int[size];
      } else {
        System.out.println("the arraysize cannot be negative!");
      }   
    } while (size  <  0);
    
    // note that the array subscript allways starts at zero.
    // you do not need to store the length of the array, rather, you can
    // access the .length instance variable which is available for every
    // array object.
    // remember an array is an object - but has a special syntax - it uses
    // square brackets.
    // For an array of integers, each value is intially set to zero.
    // If it were an array of strings - what would be the initial value?
    for (int i = 0; i < numbers.length; i++) {
      System.out.print("Enter an integer: ");
      numbers[i] = In.getInt();
    }
  }
  /** Find the largest number in the array.
   * @return the largest integer stored in the array.
   */
  public int getLargest() {
    int largest = numbers[0];
    if (numbers.length == 0) {
      throw new RuntimeException ("Empty array!!! oops!");
    } else {
      largest = numbers[0];
    }
    for (int i = 1; i < numbers.length; i++) {
      if (largest < numbers[i]) {
        largest = numbers[i];
      }
    }
    return largest;
  }
  
}