Assignment 5

Date Assigned: November 21, 2007
Date Due: December 5, 2007

Develop a java program that will generate 100 random integers between the ranges of 50 and 100. The program will compute and display the following: a) the largest number b) the smallest number and c) sort and print the array numbers in a descending order with 10 numbers per row. Use int array to generate and store the numbers.

A primer on Java arrays is found in The Essence of OOP using Java, Array Objects, Part 1

This sample program illustrates the use of arrays as well as array passing through static methods. Note that the int array is defined in the main and is not available in the object. The button array is declared in the class and every instance of the class contains this array.


An applet version on the "SampApp" is found here.

Note that applets have no main method and no console outputs. The applet is rendered in an applet-viewer or in a browser.


The first example illustrates the sorting algorithm. In this program the random numbers are generated in the main method and the sort method is a static method where the array is passed through parameter passing.

The second example illustrated the OO approach to generating the random numbers through an appropriate constructor which takes the size of the desired array. The instance method of this class – osort() sorts the numbers which are which are stored in the instance variable ary[]. You will notice that the OO design is superior to the non-oo design as the OO design encapsulates the details and provides more facility as you can create and manipulate as many objects of this class as needed.