Answered step by step
Verified Expert Solution
Question
1 Approved Answer
to be completed in Java. please answer numbers 4,5, and 6. attached are images of the class which must be modified 4) Modify the set
to be completed in Java. please answer numbers 4,5, and 6. attached are images of the class which must be modified
4) Modify the set () method so that it replaces and returns the item at the specified index. Observe and adjust for any issues due to the requested index and order as specified for the overloaded add ) method in 3) 5) Adjust the constructor that takes a Collection parameter so that it creates the Whatever with the same size as the Collection passed to it. The constructor still initializes the whatever with the contents of the Collection parameter. 6) Add another constructor that takes in a lone integer parameter. The Whatever is initially created to this size rather than the default size. 7) Add an instance method named getMode () that returns the most-occurring value in the list. The method's return type is Result, a generic interface that has two methods: AnyType mode (), which returns the most-occurring item in the list, and int count (), which returns how many times that item occurs. Tiebreak on first- occurring item of the highest frequency. The code for the Result interface will be provided to you to incorporate into your package. Do not send this interface file with your code. Note that the object you return needs to be a very simple container with the values necessary to support the interface methods. It does not include any computation logic - all work should be done by your list class. 8) Add a generic static method that takes in a (your) Whatever and performs a binary search on it. The method takes exactly two parameters: a Whatever, and the item to search for. The type of the second parameter needs to reflect what could possibly be in the Whatever instance. This method returns an int that is the index in the list where the item resides, or-1 if not found. The method header will look similar (same name but you need to revise it to make it use generics) to public static int binSearch (Whatever list, AnyType item) 5 ailld prihted materials due In this assignment you will get practice working with the book's (p. 586) ArtayList implementation. You will amend the basic ArrayList class provided in the specified otherwise. Remember that Arraylist is generic. Implement the Java class depicted below, using your own code. You may not use 1 package. All existing functionality must be the API's ArrayList class or any other API collection save arrays. Be sure to follow the specs exactly. Please keep with the spirit of the assignment or risk a significant penalty You will revise the Weiss ArrayList class with the following modifications (Note that from this point onward substitute "Whatever" with your class name - details below) 1) The list must be sorted in ascending order at all times, with no null references in the middle of the data. The list must have this order maintained at the end of public method call, so some existing methods will need to be modified. 2) Modify the add() (and any other methods as you see fit) method of the class so that each new item is inserted in sorted (ascending) order 3) Overload add() with signature specified below. This method inserts the item at the specified index, adjusting incumbent items as needed. Note that if the index insert the item at the proper index that places it in order, not the requested one. 4) Modify the set () method so that it replaces and returns the item at the specified 5) Adjust the constructor that takes a Collection parameter so that it creates the still initializes the whatever with the contents of the Collection parameter parameter is should public void add (int index, AnyType element) index. Observe and adjust for any issues due to the requested index and order as specified for the overloaded add () method in 3) Whatever with the same size as the Collection passed to it. The constructor Ctr 6) Add another constructor that takes in a lone integer parameter. The Whatever is initially created to this size rather than the default size 7) Add an instance method named getMode() that returns the most-occurring value in the list. The method's return type is Result, a generic interface that has two methods: AnyType mode (), which returns the most-occurring item in the list, and int count (), which returns how many times that item occurs. Tiebreak on first- occurring item of the highest frequency. The code for the Result interface will be provided to you to incorporate into your package. Do not send this interface file with your code. Note that the object you return needs to be a very simple container with the values necessary to support the interface methods. It does not include any 8) Add a generic static method that takes in a (your) Whatever and performs a the item to search for. The type of the second parameter needs to reflect what computation logic- all work should be done by your list class. binary search on it. The method takes exactly two parameters: a Whatever, and possibly be in the whatever instance. This method returns an int that is the index in the list where the item resides, or-1 if not found. The method header will look similar (same name but you need to revise it to make it use generics) to: public static int binSearch (Whatever list, AnyType item) 2reference types 586 inner classes and implementation of ArrayList chapter 15 figure 15.13 1 package weiss.util; private rrayList implementation (part 1) s public class ArraylistcAnyTypes extends AbstractCollection-AnyTyDe. implements ListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started