Sale!

COMP 248 – Assignment 3 Magic Matrix

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

Question 1: Magic Matrix
Magic square is an � × � matrix that is filled with the numbers 1,2,3, . . . . . , �! is a magic
square if the sum of the elements in each row, in each column, and in the two diagonals
is the same value.
6 1 8
7 5 3
2 9 4
Write a Java code to randomly generate a 3X3 matrix and check if the matrix is the
magic square. In your code you must test two features:
a. Does each of the numbers 1,2,3,….9 occur in the matrix?
b. Are the sums of the rows, columns, and diagonals equal to each other?
Sample Output could be as follows:
Sample 1:
The randomly generated matrix is:
4 3 8
9 5 1
2 7 6
Sample 2:
The randomly generated matrix is:
4 9 2
3 5 7
8 1 6
Question 2: Image Quantization
Use a one-dimensional array to solve the following problem: You want to eventually perform some
basic compression on an image. Assume that you will only be operating on a single row of the
image, and that pixel colors are represented as simple numbers in the array. You are required to
quantize the values of the pixels in the row. In other words, any pixel values appearing in a range
will assume a value in that range as indicated below. This creates redundancy that can lead to better
compression.
Overwrite the original values in the array as follows:
Pixel value Quantized value
0 to 20 10
21 to 40 30
41 to 60 50
61 to 80 70
81 to 100 90
101 to 120 110
121 to 140 130
141 to 160 150
161 to 180 170
More than 180 190
In your output you must print the array with the new, quantized values.
Sample Output could be as follows:
Sample 1:
Please input pixel values :
pixel 1 : 17
pixel 2 : 32
pixel 3 : 47
pixel 4 : 78
pixel 5 : 93
pixel 6 : 112
pixel 7 : 134
pixel 8 : 154
pixel 9 : 177
pixel 10 : 215
Quantized pixel values :
10 30 50 70 90 110 130 150 170 190
Sample 2:
Please input pixel values :
pixel 1 : 34
pixel 2 : 26
pixel 3 : 89
pixel 4 : 90
pixel 5 : 123
pixel 6 : 453
pixel 7 : 88
pixel 8 : 59
pixel 9 : 179
pixel 10 : 15
Quantized pixel values :
30 30 90 90 130 190 90 50 170 10
What to submit:
Zip the 2 source codes (the .java files only please, not the entire project) of this
assignment as a .ZIP file (NOT .RAR) using the following naming convention:
a#_studentID, where # is the number of the assignment and studentID is your student ID
number. For example, for this second assignment, student 123456 would submit a zip
file named a2_123456.zip
Submitting Assignment 3
Evaluation Criteria for Assignment 3
Source Code
Comments for all 2 questions (3 pts.)
Description of the program (authors, date, purpose) 1 pt.
Description of variable and constants 1 pt.
Description of the algorithm 1 pt.
Programming styles for all 2 questions (3 pts.)
Use of significant names for identifiers 1 pt.
Indentation and readability 1 pt.
Welcome Banner/Closing message 1 pt.
Question 1 (8 pts.)
The usage of the 2D array 2 pts.
The algorithm used to identify the magic matrix 4 pts.
The correctness of displaying the magic matrix. 2 pts.
Question 2 (6 pts.)
The usage of the array 2 pts.
Implementation of code to quantize the image 3 pts.
The correctness of displaying the result 1 pts.
TOTAL 20 pts.