Question
In Java please This lab uses things you learned in your introductory programming class. Some of those things are: constants random numbers overloaded methods passing/returning
In Java please
This lab uses things you learned in your introductory programming class. Some of those things are:
- constants
- random numbers
- overloaded methods
- passing/returning arrays
- filling and printing a one-dimensional array
- filling and printing a two-dimensional array
Just for fun, we've include a GUI to visualize your QR code!
Specifications
You will create a class QRCode that fills a grid with values that can be interpreted to visualize a QRCode image. (This is not a true QRCode but a pattern similar to one.)
Required elements
- QRCode class methods are instance methods.
- Your program will contain a main method that creates an instance of QRCode and calls its methods such that the result output is a grid dim x dim with Finder values in the upper left, lower left, and upper right corners.
- The dimension for the grid and the seed for the Random object must be passed in from the command line.
- If two arguments are not passed in from the command line, your program should use constants defined below:
- DEFAULT_DIMENSION 30
- DEFAULT_SEED 160
================ Class Name ================
QRCode
============= Private Variables ============
- grid : int[][]
============== Public methods ==============
+ createPattern(dim : int, seed : int) : int[]
+ setGrid(dim : int, pattern : int[]) : void
+ getGrid() : int[][]
+ setFinder(xPos : int, yPos : int) : void
- fillSquare(startX : int, startY : int, width : int, color: int) : void // possible helper method
+ print() : void
+ print(pattern : int[] ) : void
+ print(matrix : int[][]) : void
Method specifications
createPattern returns a new one-dimensional array the size of dim squared. The array should be filled with random 0's and 1's which are generated by a java.util.Random object constructed with the given seed.
setGrid takes in the dimension dim and instantiates a two-dimensional array size of dim by dim. The grid is then filled row by row from the pattern provided by the one-dimensional pattern passed in.
getGrid returns a representation of the grid member.
setFinder overwrites the existing grid with the Finder pattern described here, placing a finder in each of the upper left, upper right, and lower left corners of the grid. If a grid is null, it returns null. The upper left corner of a Finder pattern is given by the parameters xPos and yPos which are the column and row, respectively, in the class member grid. - The output border is two pixels in width. All values are set to 1 (WHITE in the GUI). - The next inner border is two pixels in width. All values are set to 0 (BLACK in the GUI). - The next inner border is two pixels in width. All values are set to 2 (WHITE in the GUI). - The innermost box is 3x3 pixels. All values are set to 3 (BLACK in the GUI).
print outputs the class member grid as a two-dimensional grid with no spaces between values in a row
print(pattern) outputs the one-dimensional pattern passed a a parameter as a two-dimensional grid with no spaces between values in a row
print(matrix) outputs the two-dimensional matrix passed as a parameter row by row with no spaces between values in a row
Testing
Things to test for are the correct number of command line arguments, a null pointer passed in if a pattern, grid, or matrix parameter structure has not actually been created yet, and the values of the Finder are as expected, among other things you can thing of. Using the visualization testing program we provided will help verify the Finder values, plus you can pick out the pattern in the output too.
Here is an example of the code with the GUI: QR code with default values
Output with default values:
111111111111111100111000100001111001001010010111111111111111
111111111111111111100110110001111001100101011111111111111111
110000000000011110000010101000010001110010111110000000000011
110000000000011100011101011111000010101101111110000000000011
110022222220011011011011010111110101101111001110022222220011
110022222220011110100011111011110001000000110110022222220011
110022333220011000101001001110010100011111111110022333220011
110022333220011001100111001101000000000001000110022333220011
110022333220011010110001101101011101010110001110022333220011
110022222220011110011101001010001010010100001110022222220011
110022222220011011111001001000001011011110101110022222220011
110000000000011101011001010110111001101110000110000000000011
110000000000011011111010110010110011100011110110000000000011
111111111111111000100011011101001111111110000111111111111111
111111111111111100001010101010110000110011101111111111111111
111010011110011101000010110010011111011001110111010011110110
000101010100001101110011011110110110011101101111010110001111
110100101011110101110000110010110100010011000101110110101101
100000110010100011101001010010111111111100011110011010101000
111101011110110111101111011100100000000100110001101111010000
101110100000100101101110110110010101111011010101000010110001
100000111011011000011010000000111010101011100011001001111111
110101011100100011111101111100010111100100111010001010000010
101101110000010101101111101011011110110001001011111000001101
001100010011100011101111000110000100111001001001000010011101
101001000101110000110001011011111011111001010111101111110010
001100110000000001011100110000001111000011010100101000101000
110000000000111100010111101100000100101110110100101100111010
000010100110101110101110110000100100110111100010010001101001
010010111100010000101100111001101100110001111001111100010100
000100010001001001100111111100000011111010101101000000110111
100001111011001110110011001011010001100011101000111001101010
010111101000100011000010101011000000101111101001000000011110
010010001001101001110000000001010001111010111100110110111001
001101111011100110111110100000010110100111100111100110111100
010101000111001100000011111010011111001011000010000001000011
110110110011110100001111010101101111010110110110110010000000
001011111000100100100110010101011110111111101101011001001000
000010101100100100011100010001101101010101110110110000100000
010010001010100110001001111001111100111010000011011001000001
001111110001011011100010010110111100110001111111111110111110
011100011000011011000001000001001011100111110110000011001000
101001001010110110110010010011001011010011011100000011011101
011011010010000111110101100011101111011000111011100001000101
101110100001011001111100111001001010110111111100010000100011
111111111111111110011000001011000100111000111110010101011100
111111111111111000001001111101100110000010001000010000011001
110000000000011001000000010101000111010111001011101100101101
110000000000011110011000101000001101101111000011100110011100
110022222220011111001101101000011011011001001010100011110000
110022222220011101111010101010011101110111100101111011100011
110022333220011101101011011010010010100101010100011101010110
110022333220011001111000110010110000001010000000101100101001
110022333220011111000101101111100001011110100010010011100100
110022222220011000111110001000000010000111001000010101101110
110022222220011010101011001101011010001111011100000001101111
110000000000011011111100011011101011111110010000111000101001
110000000000011011000111011100001001111110110110100010011011
111111111111111001000110101111000110111110010101000111000110
111111111111111100101111000011000000011001101101101011000111
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started