Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming. Please write the code in Java. Scammers will be reported. 1. Create a static void method that takes an ArrayList as its input

Java Programming.

Please write the code in Java.

Scammers will be reported.

image text in transcribed

1. Create a static void method that takes an ArrayList as its input parameter and outputs each element of the ArrayList to the screen - You can use this function as a template to get started: public static void PrintList(ArrayList list) - You are required to iterate through the list. You may use an iterator or a for loop, but go through the list and print each item. - Do not simply call System.out.println(list); This will not receive full credit. 2. In the main method: A. Create an ArrayList of doubles - Add the following values to the list in this order - 1.5 - First value - 2.35 - Second value - 4.7 - Third value - 0.01 - Fourth value B. Print the list using the PrintList method designed in step 1. C. Sort the list by calling the Collections.sort method - This method takes a single parameter, the list you want sorted. - There is an option for a second parameter, the comparator function to use, but we aren't going to use it. Only pass one parameter to Collections.sort. D. Print the list again using the PrintList method E. Call the Collections.binarySearch method to search the list for the value 1.5. - This method takes two parameters, the list you want to search and the value you want to search for ( 1.5 in this case). - This method returns an integer value. This is the index of the item that was found. F. Print the index where 1.5 was found. G. Call the Collections.fill method to zero out the list. - This method takes two parameters, the list you want to change and the value you want to fill it with ( 0.0 in this case). H. Print the list again using the PrintList method The lecture, textbook and assignment details should be sufficient to use these Collections methods. However, if you want more information here are some useful links from Java's documentation: https://docs.oracle.com/javase/7/docs/api/java/util/Collections.htmlifsort(java.util.List? httns://docs.oracle.com/javase/7/docs/api/java/util/Collections.html\#binarySearch(java.util.List, \& 20T) B https://docs.oracle.com/javase/7/docs/api/java/util/Collections.htmlifill(java.util.List.\%20T) Output: Example Output: Original List: 1.5 2.35 4.7 0.01 Sorted List: 4.7 0.01 1.5 2.35 Found 1.5 at index 2 Zero List: 0.0 0.0 0.0 0.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

What is the exception to the single fair value measure rule?

Answered: 1 week ago

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago

Question

5. Identify and describe nine social and cultural identities.

Answered: 1 week ago