Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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

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

Recommended Textbook for

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

How to solve maths problems with examples

Answered: 1 week ago