Question: Part 1: Arrays and Variables Create the Scanner variable with the following code: Scanner input = new Scanner(System.in); Create an ArrayList named myAL, with a
Part 1: Arrays and Variables
Create the Scanner variable with the following code: Scanner input = new Scanner(System.in);
Create an ArrayList named "myAL", with a datatype of Integer and a size of 3. (You must use an ArrayList, not an Array.)
Part 2: Input and User Prompts
Prompt the user with the following text (exactly): Input a number between 6 and 10
Store the user's input in the next available position in the ArrayList (myAL).
Prompt the user with the following text: Input a number between 11 and 15
Store the user's input in the next available position in the ArrayList (myAL).
Prompt the user with the following text: Input a number between 1 and 5
Store the user's input in the next available position in the ArrayList (myAL).
Part 3: Custom Method for Sorting and Printing
Create a custom method within the class with the following details:
Use the keywords public, static, and void.
Name this method "sortandprint" (without the quotation marks).
Give the method one input parameter, like this: (ArrayList
Add opening and closing curly brackets to contain the method's code, then continue with the following details inside the custom method:
Print "Unsorted ArrayList: " and then display the ArrayList on the same line. (Use the + sign to add the ArrayList to the line.)
Sort the ArrayList using the following command: Collections.sort(myAL)
Print "Sorted ArrayList: " and then display the ArrayList on the same line.
Note: To locate this method correctly, look for the code comment "Place your custom method below this line (for sorting and printing)". Make sure you do not delete the last line of the program, which includes the tag "do not delete this line".
Part 4: Call the Method
Return to Main() and, below the code you wrote previously to accept the user's input values, call (by its name) the custom method you wrote in Part 3 ("sortandprint"). Input the ArrayList as the input parameter.
Part 5: Search
Prompt the user with the following text: "Enter the number you wish to search for: "
Store the user's input in a new integer variable named "searchvalue".
Create a boolean variable named "answer".
Assign (=) to answer the following command: myAL.contains(searchvalue);
Part 6: Report Search Result
Write an IF statement with the following condition: (answer)
If answer evaluates true, output with the following code: "This list contains " + searchvalue
If answer evaluates false, output with the following code: "This list does not contain " + searchvalue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
