Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

}

image text in transcribed

public class MyArray { int[] nums; int numElements; public MyArray(int[] numbers) { nums = new int[numbers.length]; for(int i=0;i= count) return; int[] new_nums = new int[count]; for(int i=0;i

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_2

Step: 3

blur-text-image_3

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