Starting from:

$25

CSE110 - Principles of Programming with Java - Lab 10 - Solved

- Lab 10  

This lab is for practicing the object-oriented programming, and you need to implement a Student Class and implement a simple system to modify and view user information. 

Use the following Coding Guidelines:  

•  When declaring a variable, you usually want to initialize it.  

•  Use white space to make your program more readable.  

•  Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs.  


Getting Started  

Create a class called Lab10. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab10.java.  

 

The instructions of the assignment are as follows: 

 

// import all and anything you need  

//-->  

 

public class Lab9  

{  

 

//Declare the main method  

//-->  

{  

Scanner in = new Scanner(System.in);  

 

// Create four 4 x 4 matrices (2D Integer Array) mat_A, mat_B, mat_C and mat_D 

//Hint: Read the values row wise  

//For example: If the input is 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16.  

//Then matrix will be: 

1   2   3   4   

5   6   7   8   

9   10  11  12  

13  14  15  16 

 

 

//Declare three 2D arrays with 4 rows and 4 columns an example is shown below 

//int [] [] mat_A = new int [4] [4];  

 

// Similarly create mat_B, mat_C and mat_D 

// -->  

// -->  

// -->  

 

// Read vales into matrix A and B 

// Print "Enter values into mat_A:"  

// -->  

 

// Display the mat_A 

// Print “Matrix A is ” for(int i = ?  ;  ??  ;  ?){ 

                   for(int j = ?  ;  ??  ;  ?){ 

 

                       // -->  

                } 



 

Print "Enter values into mat_B:"  

// --> 

 

// Display the mat_B // Print “Matrix B is ” 

// --> 

 

Task 1: 

//Matrix Addition: Add the two matrices mat_A and mat_B and store the new matrix in mat_C for (int i = ?  ;  ??  ;  ?){ 

                   for (int j = ?  ;  ??  ;  ?){ 

 

                       // -->  

                } 



 

// Display the mat_C 

// Print “Addition of two matrices: Matrix C is ” 

// --> 

 

Task 2: 

// Calculate the sum of elements of matrix C and display the value 

// Declare an integer value <sum> 

// --> 

 

for (int i = ?  ;  ??  ;  ?){ 

                   for (int j = ?  ;  ??  ;  ?){ 

 

                       // -->  

                } 



 

// Print “Sum of elements of matric C is <sum>” 

// --> 

 

Task 3: 

//Find transpose of matrix C and store the new matrix in mat_D 

//Hint: The new matrix D will have rows which are columns of the original matric C //The transpose of the matrix mentioned in the above example will be: 

1          5   9   13   

2          6   10  14   

3          7   11   15        

4          8          12   16 

 

for (int i = ?  ;  ??  ;  ?){ 

                   for (int j = ?  ;  ??  ;  ?){ 

                       mat_D [?] [?] = mat_C [?] [?]; 

                       // -->  

                } 



 

// Display the mat_D 

// Print “Transpose of matrix C is: ” 

// --> 

 

 





 

 

Sample Input: 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 

 

Sample Output: 

Enter values into mat_A: 

1       2       3       4        

5       6       7       8        

9       10      11      12       

13      14      15      16 

      

Enter values into mat_B: 

1       2       3       4        

5       6       7       8        

9       10      11      12       

13      14      15      16 

      

Addition of two matrices: Matrix C is  

2       4       6       8        

10      12      14      16       

18      20      22      24       

26      28      30      32       

Sum of elements of matrix C is 272 

 

Transpose of matrix C is  

2       10      18      26       

4       12      20      28       

6       14      22      30       

8       16      24      32       

 

More products