|Homework #2||CMSC 131|
|Due Thursday Sept 23, 6:00 pm||Object-Oriented Programming I|
|Type of homework: Closed||Fall 2004|
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.
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 keep a log of how much time you are spending on various parts of the homework.
This homework will be graded as follows:
This homework is considered a closed homework. Please visit the course web page for information regarding the policy associated with homeworks of this course.
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), the shell (ImageProcessor.java) of the class you need to implement, the time log file, and two 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:
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: doubling the picture and posterizing it. After displaying the source picture your program will ask the user whether he/she wants to double the size of the source picture by using a dialog box with the message "Do you want to double the picture size?". Your program will proceed to double the size of the source picture and display the result if the user select "Yes", otherwise no processing will take place. Next your program will proceed to ask the user whether he/she wants to posterize the source picture. If the user selects "Yes" the source picture will be posterized and displayed, otherwise the processing associated with the source picture ends.
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. 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.
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 as follows:
|Placing side by side||$3.00|
Notice there is no cost associated with displaying the source images. 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).
You must use meaningful variable names and good indentation. You may assume that all inputs are valid. (E.g., when the user inputs an image file name, you may assume it is valid.)
The following provides an 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. We have chosen to perform all the possible manipulations (doubling, posterizing, stacking up, etc.) for the input image(s) provided. Each of the following snapshots is preceded by a description of the processing that took place.
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", the existing images are removed, you enter the number of images to process
After selecting "OK" and entering the first image name
After selecting "OK" and entering the second image name
After selecting "OK"
After selecting "Yes"
After selecting "Yes"
After selecting "No" the images are removed and the cost is displayed
Selecting "OK" ends the program
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 to 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 allow us to "concatenate" (put side by side) several images (three or more) present in a location. The standard implementation is modified as follows. If in response to the 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 of $3.00. Otherwise, the program behaves exactly as it does for the standard implementation.
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.)
Submit your project using the submit project option associated with Eclipse. Remember to complete your time log before submitting your homework.