Given the Table class of Exercise E7.17 , add a method that returns the sum of

Question:

Given the Table class of Exercise •• E7.17 , add a method that returns the sum of the ith row (if horizontal is true) or column (if horizontal is false):

public double sum(int i, boolean horizontal)

Data from Exercise E 7.17

Add a method to the Table class below that computes the average of the neighbors of a table element in the eight directions shown in Figure 15:
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; }
}


Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question
Question Posted: