Write a class named Strict that has the method equals as spe

  Write a class named Strict that has the method equals as specified in the book on page 316       (ALL CORRESPONDING ELEMENTS ARE THE SAME.) 2.    The class named Strict should also have a method        public static int  howmany(int[][] m1, int[][] m2) that returns how many cell values are identical       in the two arrays (it only counts if they are identical in the same cell.) 3.    The class named Strict should also have a method       public static int diagonal(int[][] m1, int[][] m2) that returns how many cell values are identical       along the diagonal (that is, checking only cells [0][0], [1][1], and [2][2] from the two arrays.) 4.    The class named Strict should also have a method        public static double  average(int[][] m1,int[][] m2)that returns the average of all the cell values         from  the arrays (one answer--DIVIDING BY 18.) 5.    The class named Strict should also have a method       public static void display(int[][] m1, int[][] m2) that displays only those values of the arrays that       are odd in rectangular form (row by row for each array.)       You may assume the values entered are between 0 and 99 for formatting purposes. Make it pretty! 6.    The class named Strict should also have a method        public static boolean silly(int[][] m1, int[][] m2) that returns true if the two arrays have all numbers satisfying       1 < numbers <=10  and returns  false  otherwise. 

Solution

Hi, I have implemented first four part of question.

Please repost other in separate post.

Please let me know in case of any issue with first four parts.

public class Strict {

   //2

   public static int howmany(int[][] m1, int[][] m2){

       int similar = 0;

       for(int i=0; i<m1.length && i<m2.length; i++){

           for(int j=0; j<m1[i].length && j<m2[i].length; j++){

               if(m1[i][j] == m2[i][j])

                   similar++;

           }

       }

       return similar;

   }

   //3

   public static int diagonal(int[][] m1, int[][] m2){

       int similar = 0;

       int i=0;

       while(i<m1.length && i<m2.length){

           if(m1[i][i] == m2[i][i])

               similar++;

           i++;

       }

       return similar;

   }

   //4

   public static double average(int[][] m1,int[][] m2){

       double total = 0;

       int totalElement = 0;

       // summing up m1 elements

       for(int i=0; i<m1.length; i++){

           totalElement = totalElement + m1[i].length;

           for(int j=0; j<m1[i].length; j++){

               total = total + m1[i][j];

           }

       }

       // summing up m2 elements

       for(int i=0; i<m2.length; i++){

           totalElement = totalElement + m2[i].length;

           for(int j=0; j<m2[i].length; j++){

               total = total + m2[i][j];

           }

       }

       return total/totalElement;

}

}

 Write a class named Strict that has the method equals as specified in the book on page 316 (ALL CORRESPONDING ELEMENTS ARE THE SAME.) 2. The class named Strict
 Write a class named Strict that has the method equals as specified in the book on page 316 (ALL CORRESPONDING ELEMENTS ARE THE SAME.) 2. The class named Strict

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site