Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Solve in java: Next, suppose we received this image that we knew contained parity bits applied by this technique 00110000 00111001 00011100 00111001 00110000 00111100

Solve in java:

image text in transcribedimage text in transcribedimage text in transcribed

Next, suppose we received this image that we knew contained parity bits applied by this technique 00110000 00111001 00011100 00111001 00110000 00111100 Again, we color the parity bits red so we can see them better. Suppose that we want to check to make sure that this image hasn't been altered. For each row and column, we record whether the number of 1s (NOT including the parity bits) is even or odd. We also record what we EXPECT the parity bit to be for that row or column (remembering a parity bit is 1 if there are an odd number of ls already and even otherwise) row 0: even we expect 0 for the parity bit row 1: odd-> we expect 1 for the parity bit row 2: odd--we expect for the parity bit (error: the parity bit says 0) row 3: oddwe expect 1 for the parity bit row 4: even we expect 0 for the parity bit column 0: even we expect 0 for the parity bit column 1: even->we expect 0 for the parity bit column 2: even we expect 0 for the parity bit (error: the parity bit says 1) column 3: odd--> we expect 1 for the parity bit column 4: oddwe expect 1 for the parity bit column 5: odd-->we expect 1 for the parity bit column 6: even-we expect 0 for the parity bit From this anal ysis, we can see that the bit at row 2, column 2 has been swapped. It currently shows as a 0, but we know it must be a1 because of the information in the parity bits. Thus, we can correct our image to be this (the corrected image without the parity bits listed): 0011000 0011100 0011110 0011100 0011000 Note that this simplistic technique can ONLY be used to detect if a single bit has been modified. It cannot be used to detect if more than one bit has changed, since several problems could cause the same switch in parity bits Assignment Description: Write a program that asks a user for an image file (.txt). The format of this file is discussed below, but part of the file has an image with elements that are either 0 or as well as a row and column of parity bits Your program will first detect if any bits of the original image have been tampered with, by comparing the parity bits to the Os and 1s in the image. Your program will then correct an error, if there is one, and will display the corrected image using character substitutions (from user input) for Os and 1s in the image There are four sample input files for you to download from Canvas smiley.txt (used above-contains one error) smileyErrors.txt (contains multiple errors) flower.txt (contains one error) lowerNoErrors.txt (contains no errors) Each input file will have the following format RowsxColumns (blank 1ine) the image, using 0s and 1s, including the parity row and column Here, Rows is how many rows are in the image (including the parity row) and Columns is how many columns (again, including the parity column). You may assume that Rows and Clumns are both even. Also, note that there is an x between the Rows and the Columns, so that the first line might look like 26x76 Unfortunately, Text-based File /O is not currently covered in the zyBook, but there is a reference file posted in Canvas (6 files.pdf) under Files-)Java Reference or Modules Canvas Textbook (Java). Since File I/O is not discussed in Lecture until Tuesday of Week 6, please read this document and use the code / pseudocode below to help in completing the initial portion of the program to load the contents of the file into a 2D array -Ask user for file name and store in a String (we will assume the file exists Open an input stream from the file: Scanner inFile-new Scanner(new File(filena me)); Read in the first line of the file (Example 26x76): String size-in File.nextLine0 -Parse line and use first number (26) for the number of rows and second number (76) for the number of columns in your 2D array -Read past the blank line in the file: inFile.nextLine0; Use a nested loop to read in each line from the file, parse each number in the row, andl 2D array Here is a sample run of the program: (Continued on next page) Enter name of input file: smiley.txt ff at ROW 16 Off at CoL 27 Position (16 27) was modified--correcting What character would you like to use for white? + What character would you like to use for black? - Process another file? (Yes/No): YES Enter name of input file: Output for "smileyErrors.txt" Process another file? (Yes/No): yes Enter name of input file: smileyErrors.txt Off at ROW 11 Off at ROW 16 Off at ROW 22 Off at ROW 23 Off at ROW 24 Off at COL 27 Off at COL 45 Off at COL 56 Multiple errors were detected. Image may be damaged. Output for "flower.txt" (Image not shown to save space in this document) Process another file? (Yes/No): yes Enter name of input file: flower.txt Off at ROW 3 Off at COL 16 Position (3, 16) was modified...correcting What character would you like to use for white? + What character would you like to use for black? - Requirements: 1. To simplify grading, the output must look EXACTLY like the output above. 2. Your program must store the Os and 1s from the image in a two-dimensional array. 3. After reading the file into the array, count the number of ls in each row and each column been modified. Print a message saying which position you are changing, and change it in your array then there are likely multiple changes that have been made to the original image. With our parity check technique, there is sometimes no way to tell where the errors are, since several different problems could flip the same parity bits. If you do find that multiple rows and columns are off, display the error shown in the output above and ask if they wish to process another file. Do the same if only a single row or a single column has an odd count. (Do not display the image.) 6. If every row and column has an even count of 1s, then the image has no errors. Print that message as your result. 7. If the image had either one (now corrected) or no errors, then ask the user for a character to substitute for white (the 1s) and a character to substitute for black (the 0s). Loop through your array to print the image using that substitution. DO NOT print the parity row and column 8. Ask the user if they wish to process another file if they answer Yes, YES, yes, etc. (ignore case) repeat the program. 9. Thoroughly test with ALL files. May want to create your own ASCII art test file and see if it works! Next, suppose we received this image that we knew contained parity bits applied by this technique 00110000 00111001 00011100 00111001 00110000 00111100 Again, we color the parity bits red so we can see them better. Suppose that we want to check to make sure that this image hasn't been altered. For each row and column, we record whether the number of 1s (NOT including the parity bits) is even or odd. We also record what we EXPECT the parity bit to be for that row or column (remembering a parity bit is 1 if there are an odd number of ls already and even otherwise) row 0: even we expect 0 for the parity bit row 1: odd-> we expect 1 for the parity bit row 2: odd--we expect for the parity bit (error: the parity bit says 0) row 3: oddwe expect 1 for the parity bit row 4: even we expect 0 for the parity bit column 0: even we expect 0 for the parity bit column 1: even->we expect 0 for the parity bit column 2: even we expect 0 for the parity bit (error: the parity bit says 1) column 3: odd--> we expect 1 for the parity bit column 4: oddwe expect 1 for the parity bit column 5: odd-->we expect 1 for the parity bit column 6: even-we expect 0 for the parity bit From this anal ysis, we can see that the bit at row 2, column 2 has been swapped. It currently shows as a 0, but we know it must be a1 because of the information in the parity bits. Thus, we can correct our image to be this (the corrected image without the parity bits listed): 0011000 0011100 0011110 0011100 0011000 Note that this simplistic technique can ONLY be used to detect if a single bit has been modified. It cannot be used to detect if more than one bit has changed, since several problems could cause the same switch in parity bits Assignment Description: Write a program that asks a user for an image file (.txt). The format of this file is discussed below, but part of the file has an image with elements that are either 0 or as well as a row and column of parity bits Your program will first detect if any bits of the original image have been tampered with, by comparing the parity bits to the Os and 1s in the image. Your program will then correct an error, if there is one, and will display the corrected image using character substitutions (from user input) for Os and 1s in the image There are four sample input files for you to download from Canvas smiley.txt (used above-contains one error) smileyErrors.txt (contains multiple errors) flower.txt (contains one error) lowerNoErrors.txt (contains no errors) Each input file will have the following format RowsxColumns (blank 1ine) the image, using 0s and 1s, including the parity row and column Here, Rows is how many rows are in the image (including the parity row) and Columns is how many columns (again, including the parity column). You may assume that Rows and Clumns are both even. Also, note that there is an x between the Rows and the Columns, so that the first line might look like 26x76 Unfortunately, Text-based File /O is not currently covered in the zyBook, but there is a reference file posted in Canvas (6 files.pdf) under Files-)Java Reference or Modules Canvas Textbook (Java). Since File I/O is not discussed in Lecture until Tuesday of Week 6, please read this document and use the code / pseudocode below to help in completing the initial portion of the program to load the contents of the file into a 2D array -Ask user for file name and store in a String (we will assume the file exists Open an input stream from the file: Scanner inFile-new Scanner(new File(filena me)); Read in the first line of the file (Example 26x76): String size-in File.nextLine0 -Parse line and use first number (26) for the number of rows and second number (76) for the number of columns in your 2D array -Read past the blank line in the file: inFile.nextLine0; Use a nested loop to read in each line from the file, parse each number in the row, andl 2D array Here is a sample run of the program: (Continued on next page) Enter name of input file: smiley.txt ff at ROW 16 Off at CoL 27 Position (16 27) was modified--correcting What character would you like to use for white? + What character would you like to use for black? - Process another file? (Yes/No): YES Enter name of input file: Output for "smileyErrors.txt" Process another file? (Yes/No): yes Enter name of input file: smileyErrors.txt Off at ROW 11 Off at ROW 16 Off at ROW 22 Off at ROW 23 Off at ROW 24 Off at COL 27 Off at COL 45 Off at COL 56 Multiple errors were detected. Image may be damaged. Output for "flower.txt" (Image not shown to save space in this document) Process another file? (Yes/No): yes Enter name of input file: flower.txt Off at ROW 3 Off at COL 16 Position (3, 16) was modified...correcting What character would you like to use for white? + What character would you like to use for black? - Requirements: 1. To simplify grading, the output must look EXACTLY like the output above. 2. Your program must store the Os and 1s from the image in a two-dimensional array. 3. After reading the file into the array, count the number of ls in each row and each column been modified. Print a message saying which position you are changing, and change it in your array then there are likely multiple changes that have been made to the original image. With our parity check technique, there is sometimes no way to tell where the errors are, since several different problems could flip the same parity bits. If you do find that multiple rows and columns are off, display the error shown in the output above and ask if they wish to process another file. Do the same if only a single row or a single column has an odd count. (Do not display the image.) 6. If every row and column has an even count of 1s, then the image has no errors. Print that message as your result. 7. If the image had either one (now corrected) or no errors, then ask the user for a character to substitute for white (the 1s) and a character to substitute for black (the 0s). Loop through your array to print the image using that substitution. DO NOT print the parity row and column 8. Ask the user if they wish to process another file if they answer Yes, YES, yes, etc. (ignore case) repeat the program. 9. Thoroughly test with ALL files. May want to create your own ASCII art test file and see if it works

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions