/* * Two class program with a UI and a manager class. * Generates 6 random numbers stores them in an array. * Passes the whole array as a parmater */ package arrayrandomscanner5B; public class ArrayRandomScanner5BUI { public static void main(String[] args) { int[] theArray = new int[6]; ArrayRandomScanner5BManager am = new ArrayRandomScanner5BManager(); System.out.println("Array Random Scanner UI"); theArray = am.fillRandom(); am.displayRandomArray(theArray); } // end main } ================================================================================= /* * Method 1 - Generates 6 random numbers and stores them in an array. Passes * the array back to the main method. * Private helper method - assits with the generation of the random numbers * Method 2 - Accepts the array as a parameter and prints out the array of * random numbers. */ package arrayrandomscanner5B; public class ArrayRandomScanner5BManager { private int[] randomArray = new int[6]; public int[] fillRandom() { for (int i = 0; i < randomArray.length; i++) { int theRandomNumber = generateRandom(); randomArray[i] = theRandomNumber; } return randomArray; } // end fillRandom //======================================= public void displayRandomArray(int[] arr) { int[] randomArray = new int[6]; randomArray = arr; for (int i = 0; i < randomArray.length; i++) System.out.println(randomArray[i]); } // displayRandomArray // ===================================== // This helper method is private to the manager class and generates the // random number for the calling method. // Generated random numbers from 1 to 10 inclusive. private int generateRandom() { int randomNumber = (int)(Math.random() * 10) + 1; return randomNumber; } } ========================================================================== OUTPUT run: Array Random Scanner UI 5 5 1 1 10 1 BUILD SUCCESSFUL (total time: 0 seconds)