This lab will focus on populating and traversing a two-dimensional array (matrix). Consider a 3 by 3 square containing values Vị to V9 as shown below; conveniently, these values can be represented using a matrix (two-dimensional array). Vi V2 V3 V4 Vs V6 V7 Ve V9 A square is said to be row semi-magic if the values in each of the rows sum to the same value: (Vi + V2 + V3 = V4 + Vs + V6 = V7 + Ve + V9). A square is said to be column semi-magic if the values in each of the columns sum to the same value: (Vi + V4 + V7 = V2 + Vs + Ve = V3 + V6 + V9). A matrix is said to be magic if the matrix is semi-magic in terms of its rows and its columns. Complete the three corresponding methods that determine if the given matrix is column semi-magic, row semi- magic, and magic. You may not assume the input matrix has a particular number of sides. As a positive test example, use the following magic matrix. We verify that the matrix is magic by noting that 1 + 5 + 9 = 159 8 34 6 72 8 + 3 + 4 = 6 + 7 + 2 - 15 = 1 + 8 + 6 = 5 + 3 + 7 - 9 + 4 + 2 Implement a Matrix class with a matrix as an attribute and the necessary methods. The constructor should throw an exception if the input matrix is not square. Also implement a Tester class that constructs and initializes a Matrix object and tests whether the matrix is magic.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java 

**CS101: Lab #17 - Arrays Part II**

This lab will focus on populating and traversing a two-dimensional array (matrix).

Consider a 3 by 3 square containing values \( V_1 \) to \( V_9 \) as shown below; conveniently, these values can be represented using a matrix (two-dimensional array).

```
| V1 | V2 | V3 |
|----|----|----|
| V4 | V5 | V6 |
| V7 | V8 | V9 |
```

A square is said to be **row semi-magic** if the values in each of the rows sum to the same value:

\[
(V_1 + V_2 + V_3 = V_4 + V_5 + V_6 = V_7 + V_8 + V_9)
\]

A square is said to be **column semi-magic** if the values in each of the columns sum to the same value:

\[
(V_1 + V_4 + V_7 = V_2 + V_5 + V_8 = V_3 + V_6 + V_9)
\]

A matrix is said to be **magic** if the matrix is semi-magic in terms of its rows and its columns. Complete the three corresponding methods that determine if the given matrix is column semi-magic, row semi-magic, and magic. **You may not assume the input matrix has a particular number of sides.**

As a positive test example, use the following magic matrix.

```
| 1 | 5 | 9 |
| 8 | 3 | 4 |
| 6 | 7 | 2 |
```

We verify that the matrix is magic by noting that:

- \( 1 + 5 + 9 = 15 \)
- \( 8 + 3 + 4 = 15 \)
- \( 6 + 7 + 2 = 15 \)

And for columns:

- \( 1 + 8 + 6 = 15 \)
- \( 5 + 3 + 7 = 15 \)
- \( 9 + 4 + 2 = 15 \)

**Implementation Tasks:**

1. Implement a `Matrix` class with a matrix as an attribute and the necessary methods. The constructor should throw an exception if the input matrix is not square.

2
Transcribed Image Text:**CS101: Lab #17 - Arrays Part II** This lab will focus on populating and traversing a two-dimensional array (matrix). Consider a 3 by 3 square containing values \( V_1 \) to \( V_9 \) as shown below; conveniently, these values can be represented using a matrix (two-dimensional array). ``` | V1 | V2 | V3 | |----|----|----| | V4 | V5 | V6 | | V7 | V8 | V9 | ``` A square is said to be **row semi-magic** if the values in each of the rows sum to the same value: \[ (V_1 + V_2 + V_3 = V_4 + V_5 + V_6 = V_7 + V_8 + V_9) \] A square is said to be **column semi-magic** if the values in each of the columns sum to the same value: \[ (V_1 + V_4 + V_7 = V_2 + V_5 + V_8 = V_3 + V_6 + V_9) \] A matrix is said to be **magic** if the matrix is semi-magic in terms of its rows and its columns. Complete the three corresponding methods that determine if the given matrix is column semi-magic, row semi-magic, and magic. **You may not assume the input matrix has a particular number of sides.** As a positive test example, use the following magic matrix. ``` | 1 | 5 | 9 | | 8 | 3 | 4 | | 6 | 7 | 2 | ``` We verify that the matrix is magic by noting that: - \( 1 + 5 + 9 = 15 \) - \( 8 + 3 + 4 = 15 \) - \( 6 + 7 + 2 = 15 \) And for columns: - \( 1 + 8 + 6 = 15 \) - \( 5 + 3 + 7 = 15 \) - \( 9 + 4 + 2 = 15 \) **Implementation Tasks:** 1. Implement a `Matrix` class with a matrix as an attribute and the necessary methods. The constructor should throw an exception if the input matrix is not square. 2
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Recurrence Relation
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education