Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following statements that are contained in Main: int [] [] inStock

ID: 3622099 • Letter: C

Question

Consider the following statements that are contained in Main:

int [] [] inStock = new int[10][4];
int[] alpha = new int [20];
int[] beta = new int [20];
int[] gama = {11,13,15,17};
int[] delta = {3,5,2,6,10,9,7,11,1,8};

a) Write the definition of the method inputArray that prompts the user to input 20 numbers and stores the numbers in alpha.

b) Write the definition of the method doubleArray that initializes the elements of beta to 2 times the corresponding elements in alpha. Make sure that you prevent the method from modifying the elements of alpha.

c) Write the definition of the method copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to 3 times the previous row of inStock.

d) Write the definition of the method copyAlphaBeta that stores alpha into the first 5 rows of inStock and beta into the last 5 rows of inStock. Make sure that you prevent the method from modifying the elements of alpha and beta.

e) Write the definition of the method printArray that prints any one-dimensional array of the type int. Print 15 elements per line.

f) Write the definition of the method setInStock that prompts the user to input the elements for the first column of inStock. The method should then the elements in the remaining columns to 2 times the corresponding element in the previous column , minus the corresponding element in delta.

Write a complete Java Program that tests the method main and all of the methods discussed in parts “a” through “F”.

Explanation / Answer

Dear, class Test { public static void main(String[] args) { // declare the variables int [][]inStock=new int[10][4]; int []alpha=new int[20]; int []beta=new int[20]; int []gamma = { 11, 13, 15, 17 }; int []delta = { 3, 5, 2, 6, 10, 9, 7, 11, 1, 8 }; // initialize the arrays alpha, beta setZero( alpha, 20 ); setZero( beta, 20 ); // get the data into the array alpha inputAlpha( alpha, 20 ); // print the elements of array alpha printArray( alpha, 20 ); // copy elements of Gamma to inStock copyGamma( inStock, gamma ); // print the elements of array inStock printArray2( inStock, 10, 4 ); // copy the elements of alpha, beta to inStock copyAlphaBeta( inStock, alpha, beta ); // print the elements of array inStock printArray2( inStock, 10, 4 ); // set the elements of the array inStock setInStock( inStock, delta ); // print the elements of array inStock printArray2( inStock, 10, 4 ); System.exit(0); } // end of function, main // initializes the elements of a given array to zero public static void setZero( int myArray[], int size ) { // initialize the array to zero for ( int i = 0; i