Question: public class HW4 { public static void main(String[] args) { //Array int[] a = {2,8,5,4,6}; System.out.println(---------------------); System.out.println(Initial Array); print(a); System.out.println(---------------------); System.out.println(Update Array: Change value in

 public class HW4 { public static void main(String[] args) { //Arrayint[] a = {2,8,5,4,6}; System.out.println("---------------------"); System.out.println("Initial Array"); print(a); System.out.println("---------------------"); System.out.println("Update Array: Changevalue in index 2 to 7"); a = update(a, 2, 7); //Changevalue in index 2 changes from 5 to 7 print(a); System.out.println("---------------------"); System.out.println("Add

public class HW4 { public static void main(String[] args) { //Array int[] a = {2,8,5,4,6}; System.out.println("---------------------"); System.out.println("Initial Array"); print(a); System.out.println("---------------------"); System.out.println("Update Array: Change value in index 2 to 7"); a = update(a, 2, 7); //Change value in index 2 changes from 5 to 7 print(a); System.out.println("---------------------"); System.out.println("Add value 3 to the end of the array"); a = add(a,3); //Add value 3 to the end of the array print(a); System.out.println("---------------------"); System.out.println("Insert value 9 into index 3"); a = insert(a,3,9); //Insert value 9 into index 3 print(a); System.out.println("---------------------"); System.out.println("Delete the value in index 3"); a = delete(a,3); //Delete the value in index 3 print(a); }

public static int[] update(int[] array, int index, int value) { array[index] = value; return array; }

public static int[] add(int[] array, int value) { int[] temp = new int[array.length+1]; for (int i=0;i

Task #1 Creating static methods (6 pts) Step 1: Compile and run the code provided in the HW4.java source code. Keep output for your records. (you may print it, or save screenshot, or copy the output to a text file) Step 2: Look closely at the code and output. Make sure you understand why this code can be considered modeling ArrayList class (find similarities and differences), . what the code is doing, how it works. Question 1. Describe briefly your understanding of "why" and "what"; do not exceed half of a page, 12 pt, single space. Step 3: Build a class called MyArrayListStatic (remember, a new Java class should be saved as a separate file). public class MyArrayListStatic Step 4: Move each method from HW4.java into the MyArrayListStatic class. Below shows the update method. Do this for ALL the methods (besides main) that are in HW4.java public class MyArrayListStatic public static intfl update (intfi array, int index, int value) array[index] - value return array: Step 5: Change your code in Hw4.java to call the methods from the class MyArrayListStatic Because the methods are static, you need to call them with "MyArrayListStatic." written before the method name System.out.println(" System.out.println("Initial Array" MyArrayListStatic.print (a) Change HW4.java to be a new Java program HW4Static.java. Step 6: Compile, run and debug your code. If done correctly, you should have no method definitions (except the main method) in your HW4Static.java file. All the other methods should be in the MyArrayListStatic.java file. Your output should be exactly the same as when you ran the original code Step 7: Move the initialization of the array (variable a) into the MyArrayListStatic class. private static inti a[2,8,5,4,6H

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!