Question: For this task, we want to create a new application called Unique. Task 6B Define a few parameters in the main method that we will

For this task, we want to create a new application called Unique.

Task 6B Define a few parameters in the main method that we will use for this application.

Scanner class variable, called keyboard, for reading input from the keyboard

Constant variable called MAX_ENTRIES, set to 5

int array variable, called buffer, of size MAX_ENTRIES

int variable, called input, for recording input from the keyboard

int variable, called count, for tracking the number of entries

Task 6C Create a loop for reading input from the keyboard

Create a do...while loop to read integer values from the keyboard. This loop should continue to read integer values from the keyboard until the maximum number of entries has been entered or a

-1 has been entered.

Task 6D Read a integer value from the keyboard and store in the array

The application should read an integer value from the keyboard and store it into input

They integer should be stored in buffer, the count buffer should be used as the index into the array.

i.e., buffer[count] = input

If the input parameter is -1, the number should not be stored and the loop should exit

If count (number of entries) exceeded MAX_ENTRIES, the loop should exit

Task 6E Display the array entries

After the entry loop terminates, create a for loop to display all elements of the array. Below is an example of how your application should look:

Enter a digit : 457

Enter a digit : 12

Enter a digit : 98

Enter a digit : 536

Enter a digit : 8

Array Elements: 457 12 98 536 8

Task 6F Replace the for loop with an enhanced for loop to display the contents of the array

A normal for loop is createdsuch as:

for ( int lp=0; lp

When using a normal for loop, the element of the arrays are referenced by the lp integer.

An enhanced loop is created such as:

for ( int lp: buffer )

When using an enhanced for loop, the value of each element are copied into the variable lp.

Task 6G Create a method called displayArray() which accepts an array as a parameter and prints out the elements of each array value, this method returns no value

The signature for this method is:

static void

displayArray( int[] buffer )

oThe main method must be modified to pass the completed array to the new method after all of the entries have been added to the array. Since the array is passed as a reference, everything associated with the array is passed with it; including the length of thearray.

Task 6H Create a method called getArray() which accepts your Scanner and an integer specifying the number of elements to create for the array.

The signature for this method is:

static int[]getArray( Scanner keyboard, int length)

o The main method must be modified so that the array is not created here, but in the getArray method instead. Since the main method will not include the reference of the array, the getArray will return the reference of the array.

O The main method should prompt the user for the number of elements to store in the array, this number must be passed to the getArray() method so an array of a proper size can be created.

O The getArray() method must create the array and then prompt the user for the values to fill in the values of the array. The array length is now of a variable length instead of using MAX_ENTRIES.

O Now that most of the work is being done in the methods, the main method should look something like the following:

public static void main(String[] args)

{

Scanner keyboard = new Scanner( System.in );

int[] buffer;

int count=0;

System.out.print( "How many elements would you like: "

);

count = keyboard.nextInt();

buffer = getArray( keyboard, count );

displayArray( buffer );

}

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!