Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSC 212 Programming 200 points Project 4 Develop a menu-based GUI program to gen

ID: 3677961 • Letter: C

Question

CSC 212                Programming            200 points

                                   Project 4

Develop a menu-based GUI program to generate a matrix of 75X75 of integers 0 or 1 using the random number generator in the Math class. Use the following formula:

(int) (Math.random()+0.8)

Display the original matrix in a grid around the whole matrix and every 5X5 blocks.

Scan the matrix, check the blocks of 5X5 (there are 20/row and 20/column) for patterns of:

                                    X=9                     y= 7                    z=13

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

Mark each pattern with different color:

X    ----   Green

Y   ----    Red

Z   ----     Blue

Draw the matrix after processing it, display only the colored cells.

You need at least two classes, one for the program interface (Project03) and another for pattern recognition operations:

Generate Original Array

Display Original Array

Detect Patterns

Display Patterns

BONUS (20 points): Gray (disable the menu items that are not available, display patterns should be grayed if detect pattern is not invoked yet)

Bonus (30 point): use wide (around 10 pixel wide) lines to show the patterns

Submit:

Java files and the executable jar file zipped into a file labeled as “your last name-your first name” through Black Board ONLY. You are responsible for getting the right files to me.

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

Explanation / Answer

sub matrix_read_file { my ($filename) = @_; open (F, $filename) || die "Could not open $filename: $!"; while ($line = ) { chomp($line); next if $line =~ /^s*$/; # skip blank lines if ($line =~ /^([A-Za-z]w*)/) { $matrix_name = $1; } else { my (@row) = split (/s+/, $line); push (@{$matrix_name}, @row;) # insert the row-array into # the outer matrix array } } close(F); } sub matrix_multiply { my ($r_mat1, $r_mat2) = @_; # Taking matrices by reference my ($r_product); # Returing product by reference my ($r1, $c1) = matrix_count_rows_cols ($r_mat1); my ($r2, $c2) = matrix_count_rows_cols ($r_mat2); die "Matrix 1 has $c1 columns and matrix 2 has $r2 rows." . " Cannot multiply " unless ($c1 == $r2); for ($i = 0; $i < $r1; $i++) { for ($j = 0; $j < $c2; $j++) { $sum = 0; for ($k = 0; $k < $c1; $k++) { $sum += $r_mat1->[$i][$k] * $r_mat2->[$k][$j]; } $r_product->[$i][$j] = $sum; } } $r_product; } sub matrix_count_rows_cols { # return number of rows and columns my ($r_mat) = @_; my $num_rows = @$r_mat ; my $num_cols = @{$r_mat->[0]} ; # Assume all rows have an equal no. # of columns. ($num_rows, $num_cols); }