1. Write a class named Strict that has the method equals as specified in the boo
ID: 3790486 • Letter: 1
Question
1. 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.
Write a public class named your n number (lowercase n) that permits the user to provide sample input like in the textbook and then displays the results of equals, howmany, diagonal , average (2 digits after the decimal point), display, and silly. Skip one line after the answer for each method is printed. DO NOT ASK FOR 18 PROMPTS. ENTER ALL THE NUMBERS AT ONCE AND USE NESTED FOR LOOPS TO PROCESS. Both classes should be in the same file.
I have the first 6 parts of the code I just need help with the last part... Thank you!
Explanation / Answer
import java.util.Scanner;
class yournnumber {
public static void main(String[] args)
{
int[][] arr1 = new int [3][3];
int[][] arr2= new int [3][3];
Scanner sc = new Scanner(System.in);
System.out.print("Enter list1: ");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j ++)
{
arr1[i][j] = sc.nextInt();
}
}
System.out.print("Enter list2: ");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j ++)
{
arr2[i][j] = sc.nextInt();
}
}
Strict s = new Strict();
if (s.equals(arr1, arr2))
{
System.out.println("two arrays are equal.");
}
int howMany = s.howmany(arr1, arr2);
System.out.println("Only " + howMany + " cells are identical");
int diagonal = s.diagonal(arr1, arr2);
System.out.println(diagonal + " diagonal elements are equal");
double average = s.average(arr1, arr2);
System.out.printf("Average of both array: %.2f ", average);
s.display(arr1, arr2);
if (s.silly(arr1, arr2))
{
System.out.println("Arrays are silly");
}
}
}
class Strict {
public static void display(int[][] m1, int[][] m2)
{
// your code here
}
public static int howmany(int[][] m1, int[][] m2)
{
// your code here.
return 0;
}
public static int diagonal(int[][] m1, int[][] m2)
{
// your code here
return 0;
}
public static boolean equals(int[][] m1, int[][] m2)
{
// your code here
return true;
}
public static double average(int[][] m1,int[][] m2)
{
// your code here
return 0;
}
public static boolean silly(int[][] m1, int[][] m2)
{
// your code here
return true;
}
}
// PLease insert your implementation of 1-6 in the above code provided.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.