Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***Need to modify Java Code below to help monitor the execution speeds of the matrix operations. PROJECT DESCRIPTION Examine the given program that performs matrix

***Need to modify Java Code below to help monitor the execution speeds of the matrix operations.


PROJECT DESCRIPTION

Examine the given program that performs matrix operations and then use some Java statements / features that will the display statement processing times of the program.


Your program is to perform matrix addition for two user - input arrays and then monitor the speed of execution of the addition process.



Modify the Program:

Modify the starter code by placing some program statements that will assist in monitoring execution speeds of the matrix operation(s). This will enable us to evaluate the performance of the operation of the program.


To perform this modification, you can use variables such as those shown below and place them at appropriate locations in the program to monitor program segment execution times.


 
long preTime = System.currentTimeMillis();   long postTime = System.currentTimeMillis();
 



Code for assignment:

import java.util.Scanner;     public class Add_Matrices   {        Scanner scan;        int matrix1[][], matrix2[][], sum[][];        int row, column;     void create() {                      scan = new Scanner(System.in);                      System.out.println("Matrix Addition");                      // the first matrix is created          System.out.println("\nEnter number of rows & columns");        row = Integer.parseInt(scan.nextLine());        column = Integer.parseInt(scan.nextLine());                      matrix1 = new int[row][column];        matrix2 = new int[row][column];        sum = new int[row][column];           System.out.println("enter the data for first matrix :");           for(int i = 0; i < row; i++)         {          for(int j = 0; j < column; j++)           {            matrix1[i][j] = scan.nextInt();          }        }                      // the second matrix is created          System.out.println("enter the data for second matrix :");                 for(int i = 0; i < row; i++) {                                        for(int j = 0; j < column; j++) {                                                    matrix2[i][j] = scan.nextInt();                    }              }        }    void display() {                        System.out.println("\nThe First Matrix is :");                            for(int i = 0; i < row; i++) {                                        for(int j = 0; j < column; j++) {                                                    System.out.print("\t" + matrix1[i][j]);                    }                    System.out.println();              }                            System.out.println("\n\nThe Second Matrix is :");                            for(int i = 0; i < row; i++) {                                        for(int j = 0; j < column; j++) {                                                    System.out.print("\t" + matrix2[i][j]);                    }                    System.out.println();              }        }            void add() {                            for(int i = 0; i < row; i++) {                                        for(int j = 0; j < column; j++) {                                                    sum[i][j] = matrix1[i][j] + matrix2[i][j];                    }              }                            System.out.println("\n\nThe Sum is :");                            for(int i = 0; i < row; i++) {                                        for(int j = 0; j < column; j++) {                                                    System.out.print("\t" + sum[i][j]);                    }                    System.out.println();              }        }  }    class MainClass {  public static void main(String args[])   {              // a class object is created               Add_Matrices obj = new Add_Matrices();              // the class object performs a sequence of actions                obj.create();              obj.display();              obj.add();        }  }


Here is a sample of the add matrices application, prior to the code modification.


Enter number of rows & columns

2

3

enter the data for first matrix :

-2 0 9

7 5 1

enter the data for second matrix :

2 7 0

6 4 5


The First Matrix is :

-2 0 9

7 5 1


The Second Matrix is :

2 7 0

6 4 5


The Sum is :

0 7 9

13 9 6



Step by Step Solution

There are 3 Steps involved in it

Step: 1

To integrate monitoring of execution speeds into the given Java code well need to modify the create display and particularly the add methods to captur... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Marketing And Export Management

Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr

8th Edition

1292016922, 978-1292016924

More Books

Students also viewed these Programming questions

Question

6-25. How is fraudulent intent established without a confession?

Answered: 1 week ago