# Homework Solution: Add a method to a Table class below that computes the average of the neighbors of a ta…

Add a method to a 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 colums) { values = new int [rows][columns]; }    public void set(int i, int j, int n) {values [i][j] = n; } ***Please help finish this code in Eclipse Java Neon and include the EXACT following code within it*** /** * Code for E7.16 * @author */ 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) { . . . } } ***Tester code below, you can use these to test your work*** import java.util.Scanner; public class TableTester { public static void main(String[] args) { Table table = new Table(4, 5); // 4 x 5 table // Fill it with a sequence of values. for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) { table.set(i, j, (3 + i) * (2 + j)); } } System.out.println("Checking values for this table"); System.out.println("t 6 9 12 15 18"); System.out.println("t 8 12 16 20 24"); System.out.println("t10 15 20 25 30"); System.out.println("t12 18 24 30 36"); System.out.println(); System.out.println("neighborAverage(1, 1): " + table.neighborAverage(1, 1)); System.out.println("Expected: 12.0"); System.out.println("neighborAverage(2, 3): " + table.neighborAverage(2, 3)); System.out.println("Expected: 25.0"); // Upper-left corner System.out.println("neighborAverage(0, 0): " + table.neighborAverage(0, 0)); System.out.println("Expected: 9.666667"); // Lower-right corner System.out.println("neighborAverage(3, 4): " + table.neighborAverage(3, 4)); System.out.println("Expected: 28.333333"); // Right-hand side System.out.println("neighborAverage(1, 4): " + table.neighborAverage(1, 4)); System.out.println("Expected: 21.6"); // Left-hand side System.out.println("neighborAverage(1, 0): " + table.neighborAverage(1, 0)); System.out.println("Expected: 10.4"); // Bottom row System.out.println("neighborAverage(3, 2): " + table.neighborAverage(3, 2)); System.out.println("Expected: 21.6"); // Top row System.out.println("neighborAverage(0, 2): " + table.neighborAverage(0, 2)); System.out.println("Expected: 14.4"); } } Thank you!

Explanation::
• Code is provided below for both the class.

Add a way to a Board assort adown that computes the mean of the neighbors of a board part in the view directions shown.

common embrace neighborAverage(int grade, int support)

However, if the part is located at the name of the adorn, apprehend barely the neighbors that are in the board. Coercion copy, if grade and support are twain 0, there are barely three neighbors.

common assort Board

{

individual int [ ] [ ] esteems;

common Board(int grades, int colums) { esteems = fantastic int [rows][columns]; }

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

***Please acceleration perfect this jurisprudence in Eclipse Java Neon and apprehend the EXACT aftercited jurisprudence amid it***

/**
* Jurisprudence coercion E7.16
* @author
*/
common assort Board
{
individual int[][] esteems;

/**
Construct a board with ardent grades and supports.
@param supports the supports in the board.
*/
{
values = fantastic int[rows][columns];
}

/**
Sets a esteem in the board.
@param i the grade of the individual to modify
@param j the support of the individual to modify
@param n the estimate to representation coercion the fantastic esteem.
*/
common null firm(int i, int j, int n)
{
values[i][j] = n;
}

/**
Returns the mean of the close parts in a board.
@param support the colum of the part.
@return the mean of the close parts.
*/
common embrace neighborAverage(int grade, int support)
{
. . .
}
}

import java.util.Scanner;

common assort BoardTester
{
common static null deep(String[] args)
{
Board board = fantastic Board(4, 5); // 4 x 5 board

// Fill it with a succession of esteems.
coercion (int i = 0; i < 4; i++)
{
coercion (int j = 0; j < 5; j++)
{
table.set(i, j, (3 + i) * (2 + j));
}
}

System.out.println(“Checking esteems coercion this board”);
System.out.println(“t 6 9 12 15 18”);
System.out.println(“t 8 12 16 20 24”);
System.out.println(“t10 15 20 25 30”);
System.out.println(“t12 18 24 30 36”);
System.out.println();

System.out.println(“neighborAverage(1, 1): ” + board.neighborAverage(1, 1));
System.out.println(“Expected: 12.0”);
System.out.println(“neighborAverage(2, 3): ” + board.neighborAverage(2, 3));
System.out.println(“Expected: 25.0”);
// Upper-left recess
System.out.println(“neighborAverage(0, 0): ” + board.neighborAverage(0, 0));
System.out.println(“Expected: 9.666667”);
// Lower-correct recess
System.out.println(“neighborAverage(3, 4): ” + board.neighborAverage(3, 4));
System.out.println(“Expected: 28.333333”);
// Correct-hand side
System.out.println(“neighborAverage(1, 4): ” + board.neighborAverage(1, 4));
System.out.println(“Expected: 21.6”);
// Left-hand side
System.out.println(“neighborAverage(1, 0): ” + board.neighborAverage(1, 0));
System.out.println(“Expected: 10.4”);
System.out.println(“neighborAverage(3, 2): ” + board.neighborAverage(3, 2));
System.out.println(“Expected: 21.6”);
System.out.println(“neighborAverage(0, 2): ” + board.neighborAverage(0, 2));
System.out.println(“Expected: 14.4”);

}
}

Thank you!

## Expert Acceptance

Explanation::

• Jurisprudence is supposing adown coercion twain the assort.
• Every subject is reflected and implemented.

Jurisprudence in java::

Assort :: BoardTester

import java.util.Scanner;
common assort BoardTester
{
common static null deep(String[] args)
{
Board board = fantastic Board(4, 5); // 4 x 5 board
// Fill it with a succession of esteems.
coercion (int i = 0; i < 4; i++)
{
coercion (int j = 0; j < 5; j++)
{
table.set(i, j, (3 + i) * (2 + j));
}
}
System.out.println(“Checking esteems coercion this board”);
System.out.println(“t 6 9 12 15 18”);
System.out.println(“t 8 12 16 20 24”);
System.out.println(“t10 15 20 25 30”);
System.out.println(“t12 18 24 30 36”);
System.out.println();
System.out.println(“neighborAverage(1, 1): ” + board.neighborAverage(1, 1));
System.out.println(“Expected: 12.0”);
System.out.println(“neighborAverage(2, 3): ” + board.neighborAverage(2, 3));
System.out.println(“Expected: 25.0”);
// Upper-left recess
System.out.println(“neighborAverage(0, 0): ” + board.neighborAverage(0, 0));
System.out.println(“Expected: 9.666667”);
// Lower-correct recess
System.out.println(“neighborAverage(3, 4): ” + board.neighborAverage(3, 4));
System.out.println(“Expected: 28.333333”);
// Correct-hand side
System.out.println(“neighborAverage(1, 4): ” + board.neighborAverage(1, 4));
System.out.println(“Expected: 21.6”);
// Left-hand side
System.out.println(“neighborAverage(1, 0): ” + board.neighborAverage(1, 0));
System.out.println(“Expected: 10.4”);
System.out.println(“neighborAverage(3, 2): ” + board.neighborAverage(3, 2));
System.out.println(“Expected: 21.6”);
System.out.println(“neighborAverage(0, 2): ” + board.neighborAverage(0, 2));
System.out.println(“Expected: 14.4”);
}
}

Assort :: Board

common assort Board

{

individual int[][] esteems;

/**

Construct a board with ardent grades and supports.

@param supports the supports in the board.

*/

{

values = fantastic int[rows][columns];

}

/**

Sets a esteem in the board.

@param i the grade of the individual to modify

@param j the support of the individual to modify

@param n the estimate to representation coercion the fantastic esteem.

*/

common null firm(int i, int j, int n)

{

values[i][j] = n;

}

/**

Returns the mean of the close parts in a board.

@param support the colum of the part.

@return the mean of the close parts.

*/

common embrace neighborAverage(int grade, int support)

{

/*

* Declaring and initializing embrace unsteady named acceptance.

* It stores mean esteem of neighbor.

*/

embrace acceptance=0;

/*

* Primitive I ahve created span integer unsteadys to store

* estimate of grades and supports.

*

*/

//r stores sum grades in esteems board

int r = esteems.length;

// c stores sum supports in esteems board.

int c = esteems[0].length;

/*

* We primitive reflect 4 subjects of part entity at recess

*

*/

if(row==0 && support==0){

/*

* Subject 1 :: culmination left recess i.e grade=0 and support=0

*/

}

else if(row==0 && support==c-1){

/*

* Subject 2 :: culmination correct recess i.e grade=0 and support=c-1

*/

}

else if(row==r-1 && support==0){

/*

* Subject 3 :: floor left recess i.e grade=r-1 and support=0

*/

}

else if(row==r-1 && support==c-1){

/*

* Subject 4 :: floor correct recess i.e grade=r-1 and support=c-1

*/

}

else if(row==0 && support>0 && support<c-1){

/*

* Subject 5 :: Culmination grade excluding support esteems are 0<column<c-1

* Here there are five esteems

*/

}

else if(row==r-1 && support>0 && support<c-1){

/*

* Subject 6 :: Floor grade excluding support esteems are 0<column<c-1

* Here there are five esteems

*/

}

else if(row>0 && grade<r-1 && support==0){

/*

* Subject 7 :: 0<row<r-1 and support==0 i.e Primitive support withextinguished edges

* Here there are five esteems

*/

}

else if(row>0 && grade<r-1 && support==c-1){

/*

* Subject 8 :: 0<row<r-1 and support==c-1 i.e Last support withextinguished edges

* Here there are five esteems

*/

}else{

/*

* Here is the public subject of view neighbors

*/