Java Objective: Design and implement simple matrix manipulation techniques. Details: Your java program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation  loop to make sure the values are greater than 0.  • Read the elements of M1 in row major order • Print M1 to the console; make sure you format as a matirx • Repeat the previous steps for a second matrix M2 • Create a matrix M3 that is the transpose of M1 and print it to the console • Check if M1 and M2 can be added (should have the same dimensions). If possible, add M1  and M2 and print the result to the console. Otherwise print an error message. • Multiply M1 and M2 if possible and print to the console. If the matrices cannot  be multiplied, print an error message.  Implementation requirements: • Use a helper method for reading a positive integer using an input validation loop. • Use a helper method for printing a matrix.  Your helper methods should be private and static, and called in the main method. Example run: Enter number of rows for M1 -2 Invalid value 2 Enter number of columns for M1 3 Enter elements for M1, in row major order 1 2 3 4 5 6 M1: 1 2 3 4 5 6 Enter number of rows for M2 2 Enter number of columns for M2 3 2 Enter elements for M1, in row major order 4 5 6 7 8 9 M2: 4 5 6 7 8 9 M3 (transpose of M1): 1 4 2 5 3 6 M1 + M2: 5 7 9 11 13 15 Formatting Requirements • Follow indentation rules • Use descriptive variable names • Comment your code

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 12PP: (Data processing) The answers to a true-false test are as follows: T T F F T. Given a twodimensional...
icon
Related questions
Question

Java Objective:
Design and implement simple matrix manipulation techniques.
Details:
Your java program should use 2D arrays to implement simple matrix operations.
Your program should do the following:
• Read the number of rows and columns of a matrix M1 from the user. Use an input validation 
loop to make sure the values are greater than 0. 
• Read the elements of M1 in row major order
• Print M1 to the console; make sure you format as a matirx
• Repeat the previous steps for a second matrix M2
• Create a matrix M3 that is the transpose of M1 and print it to the console
• Check if M1 and M2 can be added (should have the same dimensions). If possible, add M1 
and M2 and print the result to the console. Otherwise print an error message.
• Multiply M1 and M2 if possible and print to the console. If the matrices cannot 
be multiplied, print an error message. 
Implementation requirements:
• Use a helper method for reading a positive integer using an input validation loop.
• Use a helper method for printing a matrix. 
Your helper methods should be private and static, and called in the main method.
Example run:
Enter number of rows for M1
-2
Invalid value
2
Enter number of columns for M1
3
Enter elements for M1, in row major order
1 2 3 4 5 6
M1:
1 2 3
4 5 6
Enter number of rows for M2
2
Enter number of columns for M2
3
2
Enter elements for M1, in row major order
4 5 6 7 8 9
M2:
4 5 6
7 8 9
M3 (transpose of M1):
1 4
2 5
3 6
M1 + M2:
5 7 9
11 13 15
Formatting Requirements
• Follow indentation rules
• Use descriptive variable names
• Comment your code

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning