LD09: ColorFill due Wed 20 Mar 10:00

\begin{purpose}
In this assignment you will:
\begin{itemize}
\item Study cod...
...Be introduced to pixel-based image representation.
\end{itemize}
\end{purpose}

Preparation for Lab Day

Do these steps:
  1. In your workspace, make sure you have the latest homework files from the base repository. This will create a hw09 directory in which you will do your work.

  2. You may be familiar with the concept of ASCII art. The basic idea is that you use letters and symbols available on a typical keyboard to create pictures. Take a moment to look at the four ASCII art images in hw09 directory.

  3. In your repository (in the hw09 directory) create a document called answers.txt and in it record your answers to the following questions.

  4. Each of the images begins with two numbers. What do you think is the meaning of those numbers?

  5. Now take a look at Driver.java. Notice it refers to a non-existent class called MyCanvas. The purpose of MyCanvas is to allow an ASCII image to be loaded and have parts of the image filled with a “color” (conceptually, each character/symbol on the keyboard represents a different color). Of course if you are filling an area of an image with a color there needs to be some sort of “stop character” that marks a boundary which the filling should not cross.

  6. Based on the description just given and based on how the MyCanvas class is being used, create an ASCII-ish UML diagram for this class. Include the private attributes you guess will probably be helpful in implementing the class. HINT: You will probably need a 2-dimensional array, among other things. Example of ASCII-ish UML diagram:
    =========================
            MyCanvas
    =========================
     - type attr1
     - type attr2
    =========================
     + type method1(params)
     + type method2(params)
    =========================
    

  7. Add and commit your answers.txt document which contains your answer to the questions and the UML diagram.

Lab Day

Begin by showing your prelab work to the instructor. Then do these steps:

  1. Create a new document MyCanvas.java and begin implementing the MyCanvas class you considered in the pre-lab assignment. Create private attributes and describe their purpose. Also, provide JavaDoc comments for the class. Attributes should include a 2d array of char variables along with the number of rows and columns currently in use. At some point you will need to store the identified “border character” as well. (You can always change/add something later if needed.)

  2. Go ahead and create a load() method, but for the moment don't worry about loading an image from a file. Instead, reserve memory for a $3 \times\ 4$ array of characters. Then manually fill in the 12 slots with whatever characters you want. Also, set the attributes that store image size appropriately. Make sure your work compiles.

  3. Now write the show() method which should display the image appropriately. Your show method should not be hard-coded to work only with the $3 \times\ 4$ array. Its limits should be based on the attributes of the class.

  4. Test your show() method and then document it. Commit your progress.

  5. Modify your load() method so it will accept the name of an ASCII art document as a parameter and will reserve memory for the characters:
    1. Add a parameter to accept the name of a file.
    2. In your driver pass image1.txt as a parameter when calling load().
    3. Using Scanner open the file and close it. Use try-catch or throws to handle the exception. Verify that your code will compile and run.
    4. Begin by reading the number of rows and columns on the first line of the file. Store the values in the appropriate attributes.
    5. NOTE: Scanner does not have a .nextChar() method so you will have to read one line at a time. Once you have read the line you can either copy the individual characters into your 2d array or you can use String's .toCharArray() method to convert the letters in a single command. Depending on which approach you take will affect how you reserve memory for the array. Start by reserving memory and read/store just one line of the file.
    6. Once the first row is correctly being read and stored, go ahead and read the entire file.
    7. Test, document, commit, push.