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 20:40
Convert and simplify the following sentences to conjunctive normal form (cnf): (a) (p β†’ (q β†’ r)) β†’ (p β†’ (r β†’ q)) (b) (p ∧ q) β†’ (Β¬p ↔ q) (c) ((p β†’ q) ∧ Β¬q) β†’ Β¬p
Answers: 3
question
Computers and Technology, 22.06.2019 07:20
Write a pseudocode solution for each of these problems. 1. design a while loop that lets that user enter a number. the number should be multiplied by 10, and the result stored in a variable named product. the loop should iterate as long as product contains a value less than 100. 2. design a do-while loop that asks the user to enter two numbers. the numbers should be added and the sum displayed. the loop should ask the user whether he or she wishes to perform the operation again. if so, the loop should repeat; otherwise it should terminate. 3. design a for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 100. 4. design a nested loop that displays 10 rows of # characters. there should be 15 # characters in each row. 5. convert this for loop to a while loop. declare integer count for count = 1 to 50 display count end for 6. find the error in the following pseudocode. declare boolean finished = false declare integer value, cube while not finished display β€œenter a value to be cubed.” input value; set cube = value ^ 3 display value, β€œ cubed is β€œ, cube end while
Answers: 2
question
Computers and Technology, 22.06.2019 15:00
The three logical operators used to write compound conditions are "and," "or," and "not." a: true b: false
Answers: 2
question
Computers and Technology, 23.06.2019 12:50
Which syntax error in programming is unlikely to be highlighted by a compiler or an interpreter? a variable name misspelling a missing space a comma in place of a period a missing closing quotation mark
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
Mathematics, 05.10.2019 17:00
question
Mathematics, 05.10.2019 17:00
question
Social Studies, 05.10.2019 17:00
question
Mathematics, 05.10.2019 17:00
Questions on the website: 13722363