![eddiecas](/avatars/9441.jpg)
eddiecas
12.12.2019 •
Computers and Technology
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;
}
}
Solved
Show answers
More tips
- F Food and Cooking How to Sober Up Quickly? Important Facts and Tips...
- H Health and Medicine How to Properly Take a Blood Sugar Test?...
- H Health and Medicine Simple and Effective: How to Get Rid of Cracked Heels...
- L Leisure and Entertainment What to Bring on a Hike? Essential Items to Pack for a Safe and Enjoyable Adventure...
- L Leisure and Entertainment Couchsurfing: A New Way to Travel...
- S Style and Beauty Autotanning: Harmful or Safe?...
- F Food and Cooking 10 Ideas for a Wedding Anniversary Gift...
- H Health and Medicine How to Reduce Sweating in the Heat and Beyond: Say Goodbye to Excessive Sweat...
- F Food and Cooking Do Aphrodisiacs Really Work? Separating Fact from Fiction...
- H Health and Medicine What to Eat to Lose Weight?...
Answers on questions: Computers and Technology
- C Computers and Technology Make a Zoom Ima Join :D and we could talk about whatever...
- C Computers and Technology What is output by the following code segment? int x = 11; int y = 11; if (x != y ) { System.out.print( one ); } else if (x y) { System.out.print( two ); } else if (y = x)...
- M Mathematics 5^7 x 7x+75=90 Y all I wanna know if you want a face reveal/oorp?...
- A Arts Complete for BRAINLIST (write in your own words) 1.What does it mean an artwork is abstract?2.What inspired kandinsky to creat his artwork?3.Kandinsky paintings making the...
- E English When reading a novel, when should you revise a prediction? 1. when you start the novel 2. when you finish the novel 3. when you learn more about the characters and plot 4....
- E English It is frustrating to look around and see how many biased people there are in the world. I am really glad I don t have any biases. is an example of which kind of bias? a)....
- M Mathematics tom and tyler race starting at the bottom of their cuboids to reach a crumb in the bottom corner. If they take the fastest route, who wins?...
- P Physics You and a friend go sailing for the day. At the end of the day you need to pull the boat up onto the shore. Your friend pulls 40 degrees CW from the x-axis with 200-lbs of...
- M Mathematics ANYONE HELP ASAP PLSS...
- H History Which of these things did NOT contribute to the decline in the power of unions in the 1950s? a. investigations of illegal use of unior funds b. reports that unions were pro-socialis...
Ответ:
I don't understand your question
Explanation:
I'm sorry