subject
Computers and Technology, 12.12.2019 02:31 hehena

Complete the implementation of a generic matrix class. a matrix is a two-dimensional arrangement of elements. you access elements with a row and column index. for example,
matrixtttboard = new matrix(3,3);
tttboard. put(0,0,"x");
if (tttboard. get(1,2).equals("o"
if the matrix has many rows and columns but few elements, it doesn't make sense to allocate a large two-dimentinal array, most of whose entries are null. instead, we will only store the non-null entries in a map. we store the (i, j) element at the key with value i * columns + j. for example, in a 10 x 10 matrix, the (3,4) element has key 3 * 10 + 4 = 34.

complete the implementations of the get and put method below.
complete the following code:
import. java. util. map;
import. java. util. treemap;
public class matrix
{
public matrix(int rows, int columns)
{
this. rows = rows;
this. columns = columns;
elements = new treemap();
} //add your get and put methods here
private mapelements;
private int rows;
private int columns;
// the following method is used to check your work
public static string check(int r, int c, string s)
{
int rows = 3;
int columns = 4;
matrixm = new matrix(rows, columns);
// add letters of s diagonally
for (int i = 0; i < s. length(); i++)
{m. put(r, c,s. substring(i, i+1));
r++; if (r > = rows) r = 0;
c++; if (c > = columns) c = 0;
} //make string representing matrix content

string t = "";

for (int i = 0; i < rows; i++)

for (int j = 0; j < columns; j++)

if (m. get(i, j) == null)

t += ".";

else

t += m. get(i, j);

return t;

}

}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:30
Write code using c . (take input from user) calculate the size of a given file in kbs. in this task you will complete the function with the following prototype: float get_file_size(char * filename); the function takes the file name (address to the start of a null terminated character array) as input. the function should then open the file and find the number of bytes it contains till eof. the number of bytes divided by 1024 will give the size in kbs. if the file cannot be opened the function should return -1.
Answers: 2
question
Computers and Technology, 22.06.2019 22:20
Avariable of the data type arrays is storing 10 quantities. what is true about these quantities? a. the quantities all have different characteristics. b. the quantities all have the same characteristics. c. five quantities have the same and five have different characteristics. d. it is necessary for all quantities to be integers. e. it is necessary for all quantities to be characters.
Answers: 2
question
Computers and Technology, 23.06.2019 15:10
What role did women fill during world war ii?
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
Monica and her team have implemented is successfully in an organization. what factor leads to successful is implementation? good between different departments in an organization leads to successful is implementation.
Answers: 1
You know the right answer?
Complete the implementation of a generic matrix class. a matrix is a two-dimensional arrangement of...
Questions
question
Social Studies, 05.11.2020 17:20
question
Business, 05.11.2020 17:20
question
Mathematics, 05.11.2020 17:20
Questions on the website: 13722367