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

JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the follow

ID: 3729801 • Letter: J

Question

JAVA HELP (ARRAYS)

Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the exact size required to hold all the non-negatives values of the c. A method named arrav2roduct that accepts two arrays of type intnamed x and y and returns a corresponding x and y elements, i.e., 2dArray[wndexLwndex] = XHo index] * ywndex]; console, with each array element on a separate line values into a new int array (and maintains their sequence), and returns the new array. Note that parameter array two-dimensional array. Each element in the two-dimensional array should hold the product of the When submitted, this class should not have a main method. If you wish to test your methods, you might write a simple class that creates a Module4 object and creates & receives arrays and displays their To avoid the tedium of entering array values by hand, you might also find is useful to create arrays in your code using contents in braces, which builds an array with the exact number of elements in the sequence you provide, such as: intx = {0, 1, 2, 3} or int® y = {-1,-2, 0,-3, 5, 7, 13);

Explanation / Answer

public class Module4 {
void displayContents(int arr[])//diplay content
{
for(int i=0;i<arr.length;i++)
System.out.println(arr[i]);
}
int[] removeNegatives(int arr[])//remove -ves
{int count_negatives=0;
for(int i=0;i<arr.length;i++)//count -ves
if(arr[i]<0)
count_negatives++;
int new_arr[]=new int[arr.length-count_negatives];//create array
int k=0;
for(int i=0;i<arr.length;i++)
if(arr[i]>=0)//if +ve then keep in new array
new_arr[k++]=arr[i];
return new_arr;   
}
int[][] arrayProduct(int x[] ,int y[])
{
int Array_2d[][]=new int[x.length][y.length];
for(int i=0;i<x.length;i++)//compute product
for(int j=0;j<y.length;j++)
Array_2d[i][j]=x[i]*y[j];
return Array_2d;
  
}
}

//test

public class test {//test Module4
public static void main(String args[])
{ int x[]={0,1,2,3},y[]={-1,-2,0,-3,5,7,13},z[][];
Module4 m=new Module4();
m.displayContents(x);
m.displayContents(y);
System.out.println("After removing -ves in array y");
m.displayContents(m.removeNegatives(y));
z=m.arrayProduct(x, y);
System.out.println("Array Product is:");
for(int i=0;i<x.length;i++)
{for(int j=0;j<y.length;j++)
System.out.print(z[i][j]+" ");
System.out.println();}
}
}