Programing in Scala: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point numbers. Write separate methods to get an element (given parameters row and col), set an element (given parameters row, col, and value), and output the matrix to the console formatted properly in rows and columns. Next, provide an immutable method to perform array addition given two same-sized array.
I have taken the liberty to create and initialize 2 arrays of dimensions 2x2 in the class because I inferred from the question that the arrays must be initialized by the programmer within the class itself. If you want arrays to have user-defined rows, columns, and elements, do comment!
Array is a keyword in scala. So it will throw errors if we use it as a class name. So our class is called Arrayx.
 // We Create our multidimensional array var array2 = Array.ofDim[Flo](http://img.homeworklib.com/questions/6d1dcf70-14d5-11ec-a63b-bb980eb86686.png?x-oss-process=image/resize,w_560)
![CPU Time: 17.84 sec(s), Memory: 182880 kilobyte(s) executed in 10.039 sec(s) 2D ARRAY is: 1.0 2.0 3.0 4.0 Element at [1][1] i](http://img.homeworklib.com/questions/6d98abe0-14d5-11ec-b9f8-4b6c18ee62d0.png?x-oss-process=image/resize,w_560)
class Arrayx{
var array1 = Array.ofDim[Float](2,2) // We Create our
multidimensional array
var array2 = Array.ofDim[Float](2,2)
array1 = Array(Array(1,2), Array(3,4)) // We initialise our
multidimensional array
array2 = Array(Array(5,6), Array(7,8))
var array3 = Array.ofDim[Float](2,2)
def displayArray(){
print("2D ARRAY is: ")
println()
for(i<- 0 to 1)
{ // Traversing elements using loop
for(j<- 0 to 1)
{
print(array1(i)(j) + " ")
}
println()
}
}
def getElement(a:Int, b:Int){
print("Element at [" + a + "][" + b + "] " + "is: ")
print(array1(a)(b)) //print the element at i row and j
coloumn
println()
}
def setElement(a:Int, b:Int, value:Int){
array1(a)(b) = value //set the element at i row and j coloumn to
user defined value
print("New 2D ARRAY is: ")
println()
displayArray()
}
def sumOfArrays(){
for(i<- 0 to 1)
{
for(j<- 0 to 1)
{
array3(i)(j) = array1(i)(j)+array2(i)(j) //addition of i and j
element of both rows
}
}
print("The sum of arrays is:")
println()
for(i<- 0 to 1)
{
for(j<- 0 to 1)
{
print(array3(i)(j) + " ")
}
println()
}
}
}
object MainObject{
def main(args:Array[String]){
var a = new Arrayx()
a.displayArray()
a.getElement(1,1)
a.setElement(1,1, 22)
a.sumOfArrays()
}
}
Programing in Scala: Create a class called “Array” that implements a fixed-sized two-dimensional array of floating-point...
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...
/** * A collection of methods related to multi-dimensional arrays. */ public class Array2Lab { /** * Return whether k is in list. * Precondition: the elements of list are not null. * @param list the array to be searched. * @param k the number to search for. * @return true if k is an element of list, and false otherwise. */ public static boolean contains(Object[][] list, Object k) { return false; } /** * Create a String that...
Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This will be the 3x3 matrix. Then, input 3, 64-bit, floating-point values. This will be a single-dimensional array and is the vector. Your program will simply ask the user to enter matrix values. Remember, there are 9 of these, but they need to be stored into a 3x3 multi-dimensional array (row-major). Then, your program will ask for the vector values, which will be stored into...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
In C++
Design a class to perform various matrix operations. A matrix is a set of numbers arranged in rows and columns. Therefore, every element of a matrix has a row position and a column position. If A is a matrix of five rows and six columns, we say that the matrix A is of the size 5 X 6 and sometimes denote it as Asxc. Clearly, a convenient place to store a matrix is in a two-dimensional array. Two...
ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size. For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row. For Grade 9) Calculate the sum of positive values for each column. To obtain inputs and return the results, define appropriate type C/C++ functions. Please...
need help with this python progam using numpy Create a 4x4 two dimensional array with numbers from 1 thru 16. show this then: Change the last element by dividing it in half. Show that the original array has changed. show this then: Set all values in row 2 to zero. Show the original array contains this change show this then: Set all values in column 1 to one. Shoe the original array contains this change. show this then: Display the...
For this lab, you will work with two-dimensional lists in Python. Do the following: Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(matrix, columnIndex) Write a function display() that displays the elements in a matrix row by row, where the values in each row are displayed on a separate line. Use a single space to separate different values. Sample output from this function when it...
/** * Class that defines a method which performs matrix addition. This gives students their first practice at creating and using * the code needed for higher dimensional arrays. * * @author Matthew Hertz */ public class MatrixAddition { /** * Given two equally-sized matrices, return a newly allocated matrix containing the result of adding the two.<br/> * Precondition: a & b must have the same number of rows and each row will have the same number of columns. You...
Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...