Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

with Java Instruction : For this lab, you will implement some methods that process a given List : myPopulateRandomly, myRemoveAll and myHowManyGreaterThan, which populates a

with Java

Instruction : For this lab, you will implement some methods that process a given List: myPopulateRandomly, myRemoveAll and myHowManyGreaterThan, which populates a given List with random numbers, removes all the elements from a given List and returns the number of numbers greater than a given target number within a given List, respectively. You will NOT know the object type of the given List. In other words, the given List may be an ArrayList or a LinkedList, but you wont know which one. You need to implement these methods so that they execute as effi- ciently as possible, regardless of the object type of the given list.

2. In the Lab1 class, implement the following method public static void myPopulateRandomly(List inList, int howMany) This method 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. 4. 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 myRemoveAll. 6. In your implementation of myRemoveAll, only use the List method remove(i) for removing elements 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. Regardless, your implementation must run as efficiently as possible. 8. You dont need to have a main method, but you should thoroughly test your myPopulateRandomly, myRemoveAll and myHowManyGreaterThan methods. 9. If your code doesnt compile, then you will receive an automatic 0. 10. Make sure your methods do not crash due to a RuntimeException under any circum- stances. For example, what if an empty List is passed in?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions