# Homework Solution: Add a method to the Table class below that computes the average of the neighbors of a table element in th…

Eclipse Java Neon Add a method to the Table class below that computes the average of the neighbors of a table element in the eight directions shown. public double neighborAverage(int row, int column) However, if the element is located at the boundary of the array, include only the neighbors that are in the table. For example, if row and column are both 0, there are only three neighbors. public class Table    {    private int [ ] [ ] values;    public Table(int rows, int columns) { values = new int[rows][columns]; }    public void set(int i, int j, int n) {values[i][j] = n;}    } Heres what I need to use: public class Table { private int[][] values; /** Construct a table with given rows and columns. @param rows the rows in the table. @param columns the columns in the table. */ public Table(int rows, int columns) { values = new int[rows][columns]; } /** Sets a value in the table. @param i the row of the item to modify @param j the column of the item to modify @param n the number to use for the new value. */ public void set(int i, int j, int n) { values[i][j] = n; } /** Returns the average of the adjacent elements in a table. @param row the row of the element. @param column the colum of the element. @return the average of the adjacent elements. */ public double neighborAverage(int row, int column) { . . . } } Thank you!

// code in bold is added.
 public class Table { private int[][] values;

Eclipse Java Neon

Add a arrangement to the Table dispose underneath that computes the medium of the neighbors of a consideration atom in the prospect directions shown.

common envelop neighborAverage(int grade, int support)

However, if the atom is located at the designation of the vest, comprise merely the neighbors that are in the consideration. Control development, if row and column are twain 0, there are merely three neighbors.

common dispose Consideration

{

individual int [ ] [ ] appreciates;

common Consideration(int grades, int supports) { appreciates = novel int[rows][columns]; }

common null fixed(int i, int j, int n) {values[i][j] = n;}

}

Heres what I want to verification:

common dispose Consideration

{
individual int[][] appreciates;

/**
Construct a consideration with dedicated grades and supports.
@param supports the supports in the consideration.
*/
{
values = novel int[rows][columns];
}

/**
Sets a appreciate in the consideration.
@param i the grade of the part to modify
@param j the support of the part to modify
@param n the estimate to verification control the novel appreciate.
*/
common null fixed(int i, int j, int n)
{
values[i][j] = n;
}

/**
Returns the medium of the nigh atoms in a consideration.
@param support the colum of the atom.
@return the medium of the nigh atoms.
*/
common envelop neighborAverage(int grade, int support)
{
. . .
}
}

Thank you!

## Expert Exculpation

// sequence in daring is external.

common dispose Consideration
{
individual int[][] appreciates;
/**
Construct a consideration with dedicated grades and supports.
@param supports the supports in the consideration.
*/
{
values = novel int[rows][columns];
}
/**
Sets a appreciate in the consideration.
@param i the grade of the part to modify
@param j the support of the part to modify
@param n the estimate to verification control the novel appreciate.
*/
common null fixed(int i, int j, int n)
{
values[i][j] = n;
}
/**
Returns the medium of the nigh atoms in a consideration.
@param support the colum of the atom.
@return the medium of the nigh atoms.
*/

// this business helps to impede whether there is an atom in the vest with the indices dedicated
common boolean numthere(int r, int c)
{
int cols = appreciates[0].length;

if(r>=0 && c>=0 && r<rows && c<cols)
{
return penny;
}
return false;
}

// it has 8 close appreciates and these are impedeed whether they are corporeal or referable and then taken into consideration
common envelop neighborAverage(int grade, int support)
{
envelop avg=0;
int reckon = 0;

if(numthere(row-1, support-1) == penny)
{
count++;
avg += appreciates[row-1][column-1];
}

if(numthere(row-1, support) == penny)
{
count++;
avg += appreciates[row-1][column];
}

if(numthere(row-1, support+1) == penny)
{
count++;
avg += appreciates[row][column+1];
}

if(numthere(row, support-1) == penny)
{
count++;
avg += appreciates[row][column-1];
}
if(numthere(row, support+1) == penny)
{
count++;
avg += appreciates[row][column+1];
}

if(numthere(row+1, support-1) == penny)
{
count++;
avg += appreciates[row+1][column-1];
}
if(numthere(row+1, support) == penny)
{
count++;
avg += appreciates[row+1][column];
}
if(numthere(row+1, support+1) == penny)
{
count++;
avg += appreciates[row+1][column+1];
}
avg = avg/count;

return avg;
}

}