Create a directory in your repository named a11 and include all of the files for this assignment in the a11 directory.
Create a class named Driver that includes the following interfaces:
interface MatrixGen { Integer[][] generate(int m, int n); } interface MatrixSet { Integer[][] set(int m, int n, String pattern); } interface MatrixClone { Integer[][] clone(Integer[][] matrix); } interface MatrixPrint { void print(Integer[][] matrix); } interface MatrixCompare { int compare(Integer[][] matrix1, Integer[][] matrix2); }
In your driver class, create instances of the above interfaces using lambda expressions. You are not allowed to use methods that have been deprecated in Java 9.
- The generate method should create an m x n matrix of Integer objects, each with the value of 0. We’ll assume n and m are non-negative integers.
- The set method should create an m x n matrix of Integer objects with each object having the value of a digit (0-9) specified in the String pattern. For example, if pattern is “000111000” the corresponding matrix would be
000
111
000
If the pattern contains non-digit characters the method should return a 0 x 0 Integer matrix. If the length of the pattern is not equal to n x m, the method should return a 0 x 0 Integer matrix. We’ll assume n and m are non-negative integers.
- The clone method should return an exact copy of the matrix that is passed in as an argument. If either dimension of argument is 0 then the method should return a 0 x 0 Integer matrix.
- The print method should print the matrix to the console with each row on a separate line.
- The compare method should return:
- -1 if the sum of the Integers in m1 is less than the sum of the Integers in m2
- 0 if the sum of the Integers in m1 is equal to the sum of the Integers in m2
- 1 if the sum of the Integers in m1 is greater than the sum of the Integers in m2
© 2017 – 2019, Eric. All rights reserved.