Question
Hello! I need help with these following exercises: Setup Create a Java class called ListProcessor ListProcessor should contain all of the following methods specified in
Hello!
I need help with these following exercises:
Setup
Create a Java class called ListProcessor
ListProcessor should contain all of the following methods specified in the below exercises. (*I've done this)
I need help with:
Exercise 1: Populating Lists
Implement methods with the following headers:
public int[] filledArray(int from, int to)
and
public List filledList(int from, int to)`
These methods should return populated lists with integer values in the range from the lower bound from (inclusive) until the upper bound to (exclusive).
e.g. filledArray(0, 5); should return the following array [0,1,2,3,4]
Special cases:
If from == to, an empty list should be returned.
If to < from, an IllegalArgumentException should be thrown.
Exercise 2: Shuffling Lists
Implement methods with the following headers:
public int[] shuffled(int[] numbers)
and
public List shuffled(List numbers)
These methods should return a shuffled list of numbers, by randomly swapping elements to randomise the ordering.
requirement: You are not allowed to use Collections.shuffle(), and the argument list should notbe mutated. That is to say, you must make a local copy of the argument.
note: These two methods, as well as the pairs in exercise 3 and 4 are overloaded. In short, the compiler can distinguish between two methods with the same name based on the type(s) of the parameter(s) it is passed. Overloading should be used sparingly as it can affect readability, but in this case, it is reasonable to say that the programmer should know whether he/she is shuffling a list or an array, so naming the methods shuffleArray and shuffleList instead adds no extra information. Note that you cannot overload by return type, as overloading works only by looking at different signatures. For the official definition (with examples), please see Overloading Methods section at the bottom of this page.
I don't really understand Arrays and ArrayLists so please explain it in a simple manner so I can understand. How do I solve these exercises?
Appreciate the help! Thank you :)
Step 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