Question
In the above class MyArray, define a new method repeatWhole(int count) that directly make change to the MyArray object by repeating its entire elements without
In the above class MyArray, define a new method repeatWhole(int count) that directly make change to the MyArray object by repeating its entire elements without returning anything. For example, suppose it has {10,20,30,40}. Then repeatWhole(3) makes it have {10,20,30,40,10,20,30,40,10,20,30,40}. Hint: Use of ensureCapacity() will be helpful and additional for-loop may be necessary to handle the 'count' parameter in repeatWhole(int count).
Do NOT use any other methods of MyArray except the ones defined above or any external package such as Java ArrayList.
Your answer should include method head as well as body part. eg) returnType functionName(arguments) // head part {
// body part
}
public class MyArray { int[] nums; int numElements; public MyArray(int[] numbers) { nums = new int[numbers.length]; for(int i=0;iStep 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