Question: 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

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!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!