Question

Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D...

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

9 Transpose a matrix

10 Determine if a matrix is symmetric

11 Determine the Trace of a Matrix

12 Calculate the Determinant of a Matrix

TASK #1

Create a static method that accepts 9 integer parameters and returns a 2D integer array containing the parameters as elements in the array. Numbers should be assigned indexes in row order [0][0]...[0][1]...etc.

TASK #2

Create a static method that accepts no parameters and returns a 2D integer array containing randomly-generated values between 0 and 9. Numbers should be assigned indexes in row order [0][0]...[0][1]...etc.

TASK #3

Create a static method that accepts 3 1D integer (length 3) arrays as parameters and returns a 2D integer array containing the 1D arrays as rows in the 2D array.

TASK #4

Create a static method that accepts 2 2D integer arrays as parameters and compares the arrays to determine if they are the same. Returns true if the arrays are the same (element by element comparison) and false otherwise.

TASK #5

Create a static method that accepts 2 2D integer arrays as parameters and adds one array to the other. Returns a new 2D array which is the result of the addition.

TASK #6

Create a static method that accepts 2 2D integer arrays as parameters and subtracts one array from the other. Returns a new 2D array which is the result of the subtraction.

TASK #7

Create a static method that accepts a 2D integer as parameters and multiplies the (scalar). Returns a new 2D array which is multiplication.

TASK #8

Create a static method that accepts two 2D integer array as parameters and multiplies the arrays. Returns a new 2D array which is the product of the multiplication.

TASK #9

Create a static method that accepts a 2D integer array as its parameter. Returns a new 2D array with rows from the parameter array as columns and columns from the parameter array as rows in the returned array.

TASK #10

Create a static method that accepts a 2D integer array as its parameter. Returns true if the transpose of the array ( see slide 15 ) is equal to the parameter array (element by element comparison) and false otherwise.

TASK #11

Create a static method that accepts a 2D integer array as its

parameter. Returns an integer which is known as the trace...

calculated as shown below:

1 2 3

4 5 6

7 8 9

The trace (an integer value) is calculated by summing the values where the index i and j values are equal… [0][0], [1][1]...etc. 1+ 5+ 9 = 15

TASK #12

Create a static method that accepts a 2D integer array as its parameter. Returns an integer which is known as the determinant...calculated as shown below

The determinant (an integer value) is calculated by:

a b c

d e f

g h i

(a x e x i) + (b x f x g) + (c x d x h) – (c x e x g) – (bx d x i) – (a x f x h)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

import java.util.Random;

public class Matrix {

public static int[][] getArray(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9) {

int arr[][] = {{a1, a2, a3}, {a4, a5, a6}, {a7, a8, a9}};

return arr;

}

public static int[][] getRandomArray() {

Random rand = new Random();

int arr[][] = new int[3][3];

for (int i=0; i<3; i++) {

for (int j=0; j<3; j++) {

arr[i][j] = rand.nextInt(10);

}

}

return arr;

}

public static int[][] getArrayFromVectors(int arr1[], int arr2[], int arr3[]) {

int arr[][] = new int[3][];

arr[0] = arr1;

arr[1] = arr2;

arr[2] = arr3;

return arr;

}

public static boolean areSame(int a[][], int b[][]) {

if (a.length != b.length)

return false;

for (int i=0; i<a.length; i++) {

if (a[i].length != b[i].length) {

return false;

}

for (int j=0; i<a[i].length; j++) {

if (a[i][j] != b[i][j]) {

return false;

}

}

}

return true;

}

}

NOTE: As per Chegg policy, I am allowed to answer only 4 questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.

Add a comment
Know the answer?
Add Answer to:
Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For the program described below, document your code well. Use descriptive identifier names. Use s...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • For the program described below, document your code well. Use descriptive identifier names. Use spaces and...

    For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...

  • JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...

    JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...

  • In Java write the following array- processing methods into the same application, Lab13.java. Use the main...

    In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • Java arrays Create method named repeatedN that takes two integer parameters named range and n and...

    Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...

  • Java programming: I need to create a method that is given a 2D char array and...

    Java programming: I need to create a method that is given a 2D char array and a String that returns a part of the original 2D array. The input string will tell the method which rows from the input array need to be returned. For example, a 5x5 char array input along with a string "0 4" would return rows 1 and 5 of the input array. The String input will always be numbers divided by spaces and will not...

  • Using the following create the nessecary static methods to pass random arrays with the TempartureWithArrays and...

    Using the following create the nessecary static methods to pass random arrays with the TempartureWithArrays and Temperature classes -------------------------------------------------------------------------------------- public class TemperatureWithArrays {    public static final int ARRAY_SIZE = 5;    public static void main(String[] args)    {        int x;        Temperature temp1 = new Temperature(120.0, 'C');        Temperature temp2 = new Temperature(100, 'C');        Temperature temp3 = new Temperature(50.0, 'C');        Temperature temp4 = new Temperature(232.0, 'K');        Temperature tempAve =...

  • Create a class called Lab7b and in it implement all of the methods below. Also, write...

    Create a class called Lab7b and in it implement all of the methods below. Also, write a main method with test calls to all of these methods. Don’t forget to turn in your file to Canvas before the end of the lab today. int[][] random(int N, int start, int end) returns an N-by-N matrix of random integers ranging from start to end; int rowSum(int[][] a, int i) returns the sum of the elements in row i of the 2-D array...

  • In Java Please Create A Program For The Following; Please Note: This program should be able...

    In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT