Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 1 is: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class Day2_Lab1 { public static void main(String args[]) { List al = new ArrayList(), ll

image text in transcribed

Lab 1 is:

import java.util.ArrayList; import java.util.LinkedList; import java.util.List;

public class Day2_Lab1 { public static void main(String args[]) { List al = new ArrayList(), ll = new LinkedList();

myPopulateRandomly(al); myPopulateRandomly(ll); long start = System.currentTimeMillis(); int maxAl = findMax(al); long end = System.currentTimeMillis(); System.out.println("ArrayList findMax: max=" + maxAl + ", time=" + (end - start)); start = System.currentTimeMillis(); int maxLl = findMax(ll); end = System.currentTimeMillis(); System.out.println("LinkedList findMax: max=" + maxLl + ", time=" + (end - start));

} public static > T findMax(List inL) { if (inL.isEmpty()) return null; T max = inL.get(0); int listSize = inL.size(); for (int i = 1; i 0) max = temp; } return max; } public static final int MAX = 500000; public static void myPopulateRandomly(List inL) { for (int i = 0; i Requirements: Do the following: 1. Make sure you study Participation Activity 1.3.1 in the zyBook very carefully. You don't have to fully understand how Lists are implemented using LinkedLists and/or ArrayLists, but you should try to understand as much as possible 2. Ir the Lab1 class. implement the following method public static void myPopulateRandomly(List inList, int howMany) This mcthod populates inList with howMany randomly-generated ints. Note that inlist is either an ArrayList or a LinkedList. Regardless, your implementation must run as efficiently as possible. 3. Only use the List method add(int index, Integer element) in your implementation of myPopulateRandomly for adding elements to inlist. 1. In the Lab1 class, implement the following method: public static void myRemoveAll(List inlist) This method removes all the elements from inlist. Note that inlist is either an ArrayList or a LinkedList. Regardless, your implementation must run as efficiently as possible. 5. You CANNOT use the built-in List method removeAll in your implementation of myRemove All. 6. In your implementation of myRemoveAll, only use the List method remove(i) for removing clements from inList. 7. In the Lab1 class. implement the following method: public static int myHowManyGreaterThan(List inList, int target) This method returns the number of elements in inList that are strictly greater than target. Note that inList is either an ArrayList or a LinkedList is passed in? Requirements: Do the following: 1. Make sure you study Participation Activity 1.3.1 in the zyBook very carefully. You don't have to fully understand how Lists are implemented using LinkedLists and/or ArrayLists, but you should try to understand as much as possible 2. Ir the Lab1 class. implement the following method public static void myPopulateRandomly(List inList, int howMany) This mcthod populates inList with howMany randomly-generated ints. Note that inlist is either an ArrayList or a LinkedList. Regardless, your implementation must run as efficiently as possible. 3. Only use the List method add(int index, Integer element) in your implementation of myPopulateRandomly for adding elements to inlist. 1. In the Lab1 class, implement the following method: public static void myRemoveAll(List inlist) This method removes all the elements from inlist. Note that inlist is either an ArrayList or a LinkedList. Regardless, your implementation must run as efficiently as possible. 5. You CANNOT use the built-in List method removeAll in your implementation of myRemove All. 6. In your implementation of myRemoveAll, only use the List method remove(i) for removing clements from inList. 7. In the Lab1 class. implement the following method: public static int myHowManyGreaterThan(List inList, int target) This method returns the number of elements in inList that are strictly greater than target. Note that inList is either an ArrayList or a LinkedList is passed in

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

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

Carry out an interview and review its success.

Answered: 1 week ago