CSC110Assignment6: TwoDimensionalArrays solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

Objectives
Upon completion of this assignment, you need to be able to: • Pass parameters and return values using static methods. • Pass arguments from the command-line to the String[] args array. • Implement Java code that handles two-dimensional (2D) arrays. • Extend previously written code. • Continue building good programming skills.
Introduction
Onewell-knownsetoftasksforcomputerstodayisthemanipulationofimages.Yourwork for this assignment is to add additional methods to the class ImageFun. Each execution of theprogramwillperformeitheroneoutputtransformation(ASCII-artversionofanimage) or an image manipulation: (scaling, reflecting across the x-axis of, reflecting across the yaxis of, inverting or rotating an image). For this assignment, you will be using the command-line interface to pass in the names of the input and output files, as well as the image manipulation operation to use. NOTE: Solutions must not use a Scanner object. Toillustratehowthedatainanimagefileisrepresentedina 2Darrayofintegers,consider the very small image below that is 10 pixels wide by 10 pixels high to the far left of the following image:
If we really zoom in on this image, we can see that the image is a matrix of pixels, each representingsomeshadeofgray.A 2Darrayofintegerswithvaluesrangingfrom 0 to 255 to represent the above image can be constructed in Java. Suppose this image was in a file called happyFace.jpg. The Java statement:
int[][] image = readGrayscaleImage(“happyFace.jpg”); will return a 2D array of integers with the following values corresponding to the each cell in the image. So white will be 255, black 0, light gray 195, and dark gray 126.
QuickStart
(1) Download this pdf file and store it on your computer. (2) Create a directory / folder on your computer specific to this assignment. for example, CSC110/assn6 is a good name. (3) Save the file called ImageFun.java in your directory, as well as the computer.jpg image file. Fill the source code with the class name and the methods outlined in the following specification document.
(4) Start with the easiest methods first. See the following detailed instructions below for some tips. (5) Complete each method and test it thoroughly before moving onto the next one. Compile and run the program frequently; it is much easier to debug an error shortly after a successful and error-free run. (6) The args array in the main method specifies both the name of the input image file to read and the output image to create; it also specifies which method to run. (7) Insidethemainmethod,beginbycallingthecompletedreadGrayscaleImagemethod, asitreturnsthe 2Darrayofintegersthatrepresentstheinputimagefile.Itisthisarray that you will be copying and/or manipulating. (8) The easiest method (in our opinion) is the invert method. Once you have a converted or new array with inverted values, then pass this as a parameter to the completedwriteGrayscaleImage method.Anew jpg filewillappearinthedirectory.To see it, drag it into an open browser and see the inverted image.
DetailedInstructions
The specifications document details the what for each of the methods. In each of the following sections, we also provide information on the how of each method.
main
All of the information needed by the program will be passed in through the args array when the program is executed. (No Scanners allowed.) Supposed you have run the following from the console:
javac ImageFun.java java ImageFun computer.jpg invertTest.jpg invert The main method picks up all the words after ImageFun (the Java filename) and stores it in the args array. In the above example, args is an array of length 3 and contains {”computer.jpg”, ”invertTest.jpg”, ”invert”}. The main method needs to interpret this array and: • open the image file “computer.jpg” in the current directory, • extract the image as an array of numbers, • invert these numbers, and finally,
• convert the numbers to a new image file that is saved as “invertTest.jpg” in the current directory. The main methodfirstensuresthatthe args arrayhasatleast 3 elementsinit.Thenitsets upthevariables.Usingtheinputfilename(args[0]),callthemethodreadGrayscaleImage to create the 2D array of integers. Based on the operation name (args[2]), one of the methods in the program is called. Each method manipulates the values of the 2D array of integers (or creates a new array, depending on your preference), and returns this new or altered array. This new version is then passed to writeGrayscaleImage along with the output filename (args[1]) to create a new image file. Open the new file to see the results! Every order to run the program will be executed in the same fashion:
java ImageFun