Homework #2 CMSC 131
Due Friday Feb 18, 6:00 pm Object-Oriented Programming I
Type of homework: Closed  Spring 2005

Objective

This homework will allow you to practice object creation and method invocation (for both static and non-static methods). In addition, the homework will familiarize you with the picture infrastructure we will be using in future projects. This homework is considered a closed homework, therefore no student collaboration is allowed.  Please see the Open/Closed Policy on the class web page.

Overview

For this assignment you will write a program that allows users to manipulate jpeg images. The program will read the location of one or two images and will process the image(s) according to the preferences specified by the user. The user can repeat the above process as many times as needed. More details about the program are provided in the Specifications section. You may want to take a look at the Sample Run section before you read the detailed description.

In addition to your program, you will provide a file with the tests you used to verify the correctness of your program and a log of how much time you are spending on various parts of the homework.

This homework will be graded as follows:

Specifications

Before you read these specifications, you should access the files associated with this homework by checking out the project labeled p2. The project provides all the classes (in the form of a library) associated with the picture infrastructure, a demo file (PictureDemo.java), a ProcessingCost.java file, the shell (ImageProcessor.java) of the class you need to implement, the tests file, the time log file, and several jpeg images. The PictureDemo.java file provides an example of using some of the classes that are part of the picture infrastructure.

Picture Library (We provide)

When you check out your project you will have access to a picture library we have designed for this course. The name of the library is cmsc131PictureLib. By using the following import statement in your code:

import cmsc131PictureLib.*;

you will have access to a set of picture manipulation classes we have defined for you. The following description provides information about the classes you will have access to:

Class You Must Implement (ImageProcessor)

For this homework you are to implement a class called ImageProcessor. This class implements an image processor system where the user provides images to be processed. The processing associated with the program can be divided in two subparts: processing a single image and processing two images. Your program will start by prompting the user with "Input number of images to process (1/2)". Based on the specified number, one of the two subparts will be completed. After a subpart is completed, your program will ask the user whether he/she wants to process another image(s) by using a dialog box with the message "Do you want to process another image(s)?". If the user decides to process another image(s) your program will clear any displayed images (by using PictureUtil.clearScreen) and will repeat the process previously described. Your program will end when the user decides not to process any further image(s). Before the program ends it will print the cost associated with the processing that took place. More information regarding this cost can be found in the Cost Processing section.

To help you get started, we have provided (as part of the code distribution) the class definition and a main() method you are expected to complete in the file called ImageProcessor.java. In addition, you will find some jpeg images which we have provided in case you want to use them during the development phase of your homework.

The Sample Run section provides a sample run of the program you are expected to write. Use the example in order to define the format to follow for input and output dialog boxes.

Single Image Processing

Your program will prompt the user for the image to process using a dialog box with the message "Enter image to process". After reading the image name, your program will display the provided image. There are two picture manipulations you can apply to the provided image: generating a black and white image or selecting color components. After displaying the source picture your program will ask the user whether he/she wants to generate a black and white image by using a dialog box with the message "Do you want to generate a black and white image?". Your program will proceed to generate the black and white image and display the result if the user selects "Yes", otherwise no processing will take place. Next your program will proceed to ask the user (by displaying  the message "Do you want to select color components?") whether he/she wants to process the source image by selecting color components. If the user selects "Yes", your program will ask whether the red, green and blue components will be part of the generated image.  The Sample Run shows the set of prompt messages to use in this case.  Once the color components have been specified, your program will proceed to create and display the new image.

Two Image Processing

Your program will prompt the user for the name of the first image to process using a dialog box with the message "Enter first image to process". After reading the name your program will display the source image. Next it will prompt the user for the name of the second image to process using a dialog box with the message "Enter second image to process". This second image will be displayed as well.

There are two picture manipulations you can apply to the provided images: stacking the first image on top of the second and placing the images side by side (the first to the left of the second). After displaying the second image your program will ask the user whether he/she wants to stack up the images by using a dialog box with the message "Do you want to stack up the pictures?". If the user selects "Yes" your program will proceed to display the result of stacking up the images, otherwise no processing will take place. Next your program will proceed to ask the user whether he/she wants to place the pictures side by side by using a dialog box with the message "Do you want to place pictures side by side?". If the user selects "Yes", your program will display an image representing the result of placing the source images side by side. Otherwise the processing associated with the images ends. When placing the images side by side you will place the first image on the left side and the second on the right side.

Cost Processing

After the user has decided not to process further image(s) and before the program ends, your program must display the total cost associated with the processing that took place. The cost associated with each picture manipulation is available thought the symbolic constants that are part of the ProcessingCost class:

                     Constant Processing Cost
ProcessingCost.BLACKANDWHITE Black and white image $1.0
ProcessingCost.COLORSELECTION Color components selection $2.0
ProcessingCost.STACKINGUP Stacking up images $3.0
ProcessingCost.SIDEBYSIDE Side by side images $4.5

Note: There is no cost associated with displaying the source images. The cost for color components selection is the same regardless of the number of components selected.  The total cost must be displayed using a dialog box with the message "Total Cost:" followed by the cost as a dollar amount (i.e., using the $ sign and two decimal places).

Error Handling

Tests File

Complete the file tests.txt with the set of tests you used to verify the correctness of your program. Provide at least five tests.   The following are example of tests we can have for this homework.  By the way, these tests can not be considered part of the set you must provide.

Test #1: Correct cost computed while generating black and white image.

Example: Specify one image, enter image name (shrek-1.jpg), After selecting Yes, a black and white image appears, After selecting No, the cost is correctly computed as $1.00.

Test #2: Correct cost computed for processing two images by first stacking and then placing them side by side.

Example: Specify two images, enter image names (shrek-1.jpg, shrek-2.jpg), After selecting Yes, the images get stacked, After selecting Yes, the images are shown side by side, After selecting No, the cost is correctly computed as $7.50.

Additional Requirements

You must use meaningful variable names and good indentation.

Sample Run

The following provides a sample run of the program you need to implement. Keep in mind this is just an example and not the only scenario the program is expected to handle. Each of the following snapshots is preceded by a description of the processing that took place. 

Note: Several of our user prompts make use of a 4-parameter version of JOptionPane.showConfirmDialog:

    JOptionPane.showConfirmDialog(null, <message>, <title>, <optionType>)

where <message> refers to the user prompt (e.g., "Do you want to select color components"), <title> is a descriptive note displayed at the top of the pane (e.g., Select Components), and <optionType> is a constant that specifies which buttons are available (e.g., the constant JOptionPane.YES_NO_OPTION indicates that only the buttons for yes and no---not cancel---will be displayed). For example, the SelectComponents pane below is the result of the following command:

    JOptionPane.showConfirmDialog(null, "Do you want to select color components",
             "Select Components", JOptionPane.YES_NO_OPTION)


After starting the program and specifying the number of images to process


After selecting "OK" and entering the name of image to process


After selecting "OK"

 


After selecting "Yes"


After selecting "Yes"

 


After selecting "Yes"


After selecting "Yes"

 


After selecting "No"

 


After selecting "Yes" and entering 2

 


After selecting "OK" and entering the image name

 


After selecting "OK" and entering second image name

 


After selecting "OK"

 


After selecting "Yes"


After selecting "Yes"


 

After selecting "No"

 


After selecting "OK" the program will end

Challenge Problem

Remember that you are not required to implement the following problem. Please visit the course web page for information regarding challenge problems.

IMPORTANT: If you decide to complete the challenge problem you must provide its implementation in a separate file called Challenge.java. In other words, use ImageProcessor.java for the standard program and use Challenge.java for the challenge problem. One way to do this is to first finish the standard implementation in ImageProcessor.java (and test it), and then copy and paste its contents into Challenge.java. Then continue with the implementation of the challenge problem. Please make an entry in the time log indicating you have completed the challenge problem.

The challenge problem for this homework consists of adding a feature to your program which allows us to "concatenate" (put side by side) several images (three or more) present in a location. The side-by-side operation is the only one allowed if the user specifies 3 or more images. If the user specifies 1 or 2 images, the program behaves exactly as it does for the standard implementation.

The standard implementation is modified as follows. If in response to the prompt "Input number of images to process", the user inputs a number of 3 or more, your program will then prompt the user to "Enter the common base name". The name of each file will consist of the base name followed by a digit (1-9) followed by ".jpg". For example, if the user requests that 4 images be processed, and enters the base name "shrek-", the following four files will be combined side by side:

shrek-1.jpg    shrek-2.jpg    shrek-3.jpg    shrek-4.jpg   

You may assume that no more than 9 images will be combined. If k images are processed in this way, the total cost is increased by (k-1) times the side-by-side cost (ProcessingCost.SIDEBYSIDE).

For testing purposes, you can use the following base name (which is a web address) and combine up to 4 images. (Since the name is long, it is a good idea to copy and paste it into the JOptionPane.)

http://www.cs.umd.edu/class/spring2005/cmsc131/CourseImages/shrek-

Submission

Submit your project using the submit project option associated with Eclipse. Remember to complete your tests file and time log before submitting your homework.


Web Accessibility