Question: This exercise will use command line args, arrays, and the Random class. Your Lab7.java program will take three values on the command line. 1. a

This exercise will use command line args, arrays, and the Random class. Your Lab7.java program will take three values on the command line.

1. a small positive int representing the length of the array to be dimensioned.

2. a small positive int representing the minimum value to be put into the array.

3. a small positive int representing the maximum value to be put into the array.

You will need to modify main so that the args from the comamnd line are converted to ints.

Fill in the method at the bottom. Do not modify the line of code that seeds the Random number generator.

The starter file will not compile as given. You need to convert the args[] values to ints first.

Screen-shot of execution and output:

// LAB7.JAVA FILLS AN ARRAY WITH PSEUDO RANDOM INTS USING RANDOM CLASS

import java.io.*;

import java.util.*;

public class Lab7

{

// D O N O T M O D I F Y M A I N

public static void main( String args[] )

{

// WRITE AN IF STATEMENT THAT VERIFIES THE USER PUT 3 ARGS ON THE COMMAND LINE

// IF THERE ARE NOT THREE ARS FROM THE COAMMND LINE THEN PRINT AND ERROR MESSAGE

// AND EXIT THE PROGRAM

// IF YOU MAKE IT TO HERE, YOU HAVE 3 VALUES IN THE ARGS ARRAY

int dimension = // CONVERT THE [0] ARG TO AN int AND STORE INTO dimension

int lo = // CONVERT THE [1] ARG TO AN int AND STORE INTO lo

int hi = // CONVERT THE [2] ARG TO AN int AND STORE INTO lo

int[] array = new int[dimension];

randomFill( array, lo, hi ); // you write the code for this method below

printArray( array );

}

public static void printArray( int array[] )

{

System.out.printf("Array has %d values: ", array.length );

for( int i=0 ; i

System.out.print( array[i] + " " );

System.out.println();

}

// FILL THE ARRAY WITH RANDOM INTS

public static void randomFill( int array[], int lo, int hi )

{

Random rand = new Random( 17 ); // DO NOT REMOVE THIS LINE

// WRITE A LOOP THAT DOES THE FOLLOWING:

// FILLS THE ARRAY WITH RANDOM INTS.

// EACH RANDOM INT TACKED ONTO THE ARRAY MUST BETWEEN LO AND HI INCLUSIVE

}

} // END class

ommand Prompt C:\Users\tim\Desktopl>java Lab7 20 10 100 21 86 63 25 24 98 38 68 31 39 66 41 21 82 97 57 97 42 36 59 C: \Users\tim\ Desktop\ AT8 35 20 24 13 58 68 31 39 66 41 21 82 97 57 97 42 36 59

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!