Question: Create a Java Application, called Unique. This Java Application will read in five unique integer values between 1 and 20, displaying errors if the number

Create a Java Application, called Unique. This Java Application will read in five unique integer values between 1 and 20, displaying errors if the number is outside of the desired range or if the number is duplicate.

Use the Java Application template, Unique.java:

package unique; import java.util.Scanner; public class Unique { /* Create a method called ShowArrayList() that accepts two parameters */ /* the first parameter contains a string specifying the text string */ /* the second parameter contains an integer array of variable length */ /* this method will print the array string, followed by the elements of the array */ public static void main( String args[] ) { Scanner keyboard = new Scanner( System.in ); /* create two integer arrays; one to store the original numbers as they */ /* are entered and one to store the sorted numbers */ int count = 0; // number of uniques read int entered = 0; // number of entered numbers System.out.println( "Unique - Application to retrieve 5 unique numbers between 1 and 20" ); while( entered < raw.length ) { System.out.print( "Enter number: " ); /* Add code to read in a number from the keyboard */ // validate the Input if (( new_number > 0 ) && ( new_number <= 20 )) { // flags whether this number already exists boolean containsNumber = false; /* Write a loop to determine if the new number entered is */ /* already in the array list, set containsNumber to true */ // Add the user input to the array only if the number is not already // in the array if ( !containsNumber ) { /* Write a loop to sort the list from smallest to largest */ // Print entered list ShowArrayList( "Raw List ", raw ); // Print new list after insertion to make sure our sort works ShowArrayList( "Sort List ", sorted ); } else { System.out.printf( "%d has already been entered ", new_number ); } } else { System.out.println( "number must be between 1 and 20" ); } } } // end method getNumbers } // end class Unique 

-Insert code as indicated by the comment blocks: /* */ -Create a static method ShowArrayList(), which has two parameters: --String listName --int numbers[] -Accept a new entered number, make sure it is between 1 and 20 and verify that the number has not already been entered previously. -Create two arrays of integers; one which contains the raw entered numbers and one which contains a sorted list of numbers -As each unique number is entered, sort the unique array in incrementing order

Sample Output:

Unique - Application to retrieve 5 unique numbers between 1 and 20 Enter number: 19 Raw List : 19 0 0 0 0 Sort List : 19 0 0 0 0 Enter number: 12 Raw List : 19 12 0 0 0 Sort List : 12 19 0 0 0 Enter number: 2 Raw List : 19 12 2 0 0 Sort List : 2 12 19 0 0 Enter number: 9 Raw List : 19 12 2 9 0 Sort List : 2 9 12 19 0 Enter number: 5 Raw List : 19 12 2 9 5 Sort List : 2 5 9 12 19

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!