Question: This is java and please must follow the instruction and must put //(comment) and make simple program. Thank you 1. In this problem, we are
This is java and please must follow the instruction and must put //(comment) and make simple program. Thank you
1. In this problem, we are going to practice creating, printing, and updating arrays.
a. Create a class named ArrayPractice
b. Create an instance variable named numbers. It should be an array that holds 20 integers.
c. Create a constructor that initializes numbers. The heading should look like this public ArrayPractice(int[] num)
d. Create a method called printForward. In the method using println print the line: This prints the array forward. This method should then print the array from the beginning (first element) to the end (last element). Use print and print a space between each element. Use the enhanced for loop to print the array.
e. Create a method called printBackward. In this method using println, print the line: This prints the line backward. Use print and print the array from the end (last element) to the beginning (first element). Print all elements on one line with a space between each element. You can use any type loop you want.
f. Create a method called printOdd. In this method using println print the line: This prints the odd index variables, and then use print and print every element at an odd index. You may use any type loop you want.
g. Create a method called printEven. In this method using println, print the line: This prints the odd index values and the use print to print every element at an even index. You may use any type loop you want. Print all elements on one line with a space between each element.
h. Create a method called printFirstAndLast. In this method using println, print the line: This prints the first and last elements of the array. Print the first element in the array and the last element in the array on one line using print.
i. Create a method called addOne. Using a loop, add 1 to each element in the array and then call the method printForward. printForword().
j. Create a ArrayPracticeTester.
k. Import java.util.Randomprin;
l. Create an integer array named values. It should hold 20 values.
m. Create a random number generator by typing. Random generator = new Random();
n. Create a loop you choose the type. You will fill the array from random numbers generated. Your numbers will be between 1 and 100. Inside the loop put code to put a random number in the array. Use this code: values[i] = 1+ generator.nextInt(100);
o. After you have filled the array, create an ArrayPractice object. Put the array name in the argument. ArrayPractice ap=new ArrayPractice(values);
p. Call each of the method in the class, ArrayPractice.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
