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

E16.1 Add a method to the Table class below that computes the average of the nei

ID: 3806530 • Letter: E

Question

E16.1

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; }

}

E.17.1

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

row (if horizontal is true) or column (if horizontal is false):

Improve the program of Exercise E7.17 by adding captions for each bar. Prompt the user for the captions and data values. The output should look like this:

Egypt **********************
France ****************************************

Japan ****************************

Uruguay **************************

Switzerland **************

Explanation / Answer

Hi, I have implemented Q1.

Please repost others in separate post.

Please let me know in case of any issue in Q1.

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;

   }

   public double neighborAverage(int row, int column){

       double sum = 0;

       int count = 0;

      

       // checking max length condition

       if(row <values.length && column < values[column].length){

           if(row <values.length-1){

               sum = sum + values[row+1][column];

               count++;

               if(column < values[column].length-1){

                   sum = sum + values[row+1][column+1];

                   count++;

               }

           }

           if(column < values[column].length-1){

               sum = sum + values[row][column+1];

               count++;

           }

       }

      

       // cjeck lowest boundary condition

       if(row >=0 && column >= 0){

           if(row > 0){

               sum = sum + values[row-1][column];

               count++;

               if(column > 0){

                   sum = sum + values[row-1][column-1];

                   count++;

               }

           }

           if(column > 0){

               sum = sum + values[row][column-1];

               count++;

           }

       }

      

       return sum/count;

   }

}