Lab Exercise Ten

For this exercise you are to do the following:

    Write a Java main class to read the data file numbers.txt using the Scanner class. Add each number in the file to an ArrayList<Integer> object named numbers.

    After the numbers are read, use the for-each statement to display each number on a separate line in a JOptionPane.

    After using the for-each loop use a while loop to display the numbers.

    Finally use a counter controlled for loop to display the numbers.

    Write a method Integer getMax(ArrayList<Integer> a); that returns the largest value in the ArrayList<Integer> a.

    Add a statement to the main class to display the largest value in a JOptionPane.

    Write a method boolean isSorted(ArrayList<Integer> a); the returns true if the ArrayList<Integer> a is sorted in increasing order and returns false if not.

    Add a statement to test your method.

    Add a statement to sort the ArrayList<Integer> numbers.

    Add statements to test you methods again by displaying the last number in numbers and if numbers is sorted.

    You may use the skeleton class LabExerciseTen.

    Note the Javadoc comments for the methods in LabExerciseTen.