i have matrix class fillmatrix()
, printmatex()
methods, fraction matrix , filled using hashmap : hashmap <integer, arraylist<number>>
(with rows , colomns format)
number class addition , subtraction of fraction methods. asked make method in matrix
class addition between 2 matrices following:
the class has public void
addmatrices (matrix, matrix)
has 2 matrices arguments , calculates summation of these matrices.
i wrote code didn't work. gives me error:
incompatible types: arraylist<number>cannot converted number
here code
public void addmatrices(matrix m1, matrix m2) { hashmap<integer, arraylist<number>> matrix3 = new hashmap<integer, arraylist<number>>(); hashmap<integer, arraylist<number>> matrix1 = m1.hmap; hashmap<integer, arraylist<number>> matrix2 = m2.hmap; number ob = new number(); (int = 1; <= rows; i++) { (int j = 0; j <= cols; j++) { matrix3.put(i, ob.addition(matrix1.get(j), matrix2.get(j))); } } }
the problem variable matrix3
of type
hashmap<integer, arraylist<number>>
if want put value hashmap the following types exepected
put(integer key, arraylist<number> value);
but call addition method of number class , put result value put method , think result number. \
so problem line:
matrix3.put(i, ob.addition(matrix1.get(j),matrix2.get(j)));
either change matrix3 type
hashmap<integer, number>
or put arraylist value after addition:
list<numbers> n = new arraylist<number>(); n.add(ob.addition(matrix1.get(j),matrix2.get(j))); matrix3.put(i, n);