Question: using java finish the skeleton files package apps; import java.util.Arrays; public class MyArrayHwDemo { static void showArray(int[] nums){ if(nums == null) System.out.println(null); else{ System.out.print([); for(int

using java finish the skeleton files

package apps; import java.util.Arrays; public class MyArrayHwDemo { static void showArray(int[] nums){ if(nums == null) System.out.println("null"); else{ System.out.print("["); for(int i=0; i0) System.out.print(nums[nums.length-1]); System.out.println("]"); } } public static void main(String[] args) { MyArrayHw nums1; nums1 = new MyArrayHw(); nums1.add(10); nums1.add(3); nums1.add(8); nums1.add(4); nums1.printArray(); // printArray(4,5): 10 3 8 4 System.out.println("testing get(idx)..."); System.out.println(nums1.get(0)); // 10 System.out.println(nums1.get(4)); // null System.out.println("testing get(start,end)..."); showArray(nums1.get(1, 2)); // [3,8] showArray(nums1.get(0, 3)); // [10,3,8,4] showArray(nums1.get(3, 1)); // [4,8,3] System.out.println("testing getEvenNumbers()"); showArray(nums1.getEvenNumbers()); // [10,8,4] System.out.println("testing repeat()"); nums1.remove(4); nums1.remove(8); nums1.repeat(); nums1.printArray(); // printArray(4,5): 10 3 10 3 nums1.repeat(); nums1.printArray(); // printArray(8,8): 10 3 10 3 10 3 10 3 } }

second file :

package apps; public class MyArrayHw { int[] elements; int numElements; public MyArrayHw(){ elements = new int[5]; numElements = 0; } void printArray(){ System.out.printf("printArray(%d,%d): ",numElements,elements.length); for(int i=0; i= 0){ elements[idx] = elements[numElements-1]; numElements--; } } boolean isFull() { return numElements == elements.length; } Integer get(int idx){ if(idx <0 || idx>= numElements) return null; return elements[idx]; } int[] get(int start, int end){ // Return a new copy of the array between index 'start' and 'end' inclusive. // eg) Suppose elements = [10, 5, 20, 14, 30]. get(1,3) returns a new array [5, 20, 14] // Assume that the index start and end are valid. // If start > end, then return the elements in reverse order return null; // This is here to avoid syntax error. Change as needed } int[] getEvenNumbers() { // create and return a new array that keeps only even numbers from 'elements' // eg) Suppose elements = [3, 4, 10, 11, 8], getEvenNumbers() returns a new array [4, 10, 8] // eg) Suppose elements = [1, 2, 3, 5], getEvenNumbers() returns a new array [2] // Hint: You need to count even numbers first to allocate memory as much as needed return null; // This is here to avoid syntax error. Change as needed } void repeat(){ // Make change to the array 'elements' so that it contains the elements one more time // eg) Suppose elements = [3, 4, 10], repeat() changes it as [3, 4, 10, 3, 4, 10] // Ensure that there is enough space before repeating. } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!