|Homework #3||CMSC 131|
|Due Thursday Oct 7, 6:00 pm||Object-Oriented Programming I|
|Type of homework: Open||Fall 2004|
In his homework you will practice definition of methods for classes.
For this assignment you will write a program similar to the one you wrote for HW2. The program allows users to manipulate jpeg images by providing several picture processing options. When the program is run it will ask first for a password in order to gain access to the picture processing facilities. Once the correct password has been provided, a menu with choices will be displayed. These include options for as doubling a picture, displaying original picture, etc. Your program will continue processing user's choices until quit is selected. 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 the program, you must submit pseudocode for each of the methods you will implement and a time log.
This homework will be graded as follows:
Before you read these specifications, you should access the files associated with this homework by checking out the project labeled p3. The project provides all the classes (in the form of a library) associated with the picture infrastructure, the driver of the program (Driver.java), the shell (ImageProcessor.java) of the class you need to implement, the time log file, a pseudocode file, and several jpeg images.
Most of the classes in the picture library are from the previous homework. One new class is Inverse. This class allow us to create an "x-ray"-like transformation to an image. When you create an Inverse object you pass a reference to the object that you want to invert. Two important methods you must be aware for this project are PictureUtil.anyPicDisplayed() and PictureUtil.getLastPicDisplayed(). The first method returns a boolean indicating any picture has yet been displayed. The second one returns a reference to the last image displayed. It returns a generic object of type Picture, which can be used pretty much anywhere any of the other image types can be used. Here is an example:
Picture p = PictureUtil.getLastPicDisplayed(); PictureUtilShow(p);
The code distribution has a driver named Driver.java.You will run your program by executing the main() method associated with this driver. Notice the driver creates an instance of a class called ImageProcessor which provides all the image processing support. Your assignment consists of implementing all the methods of the ImageProcessor class.
Your program's processing can be subdivided in two parts: login into the image processing system and processing user requests. When your program starts executing it will prompt the user for a password string. The proper password must be provided in order to access the image processing system. The user has a given maximum number of attempts in order to provide a correct password. The program will terminate if the user does not provides a correct password after exhausting the allowed number of attempts. For this homework the password will be "cmsc131" and and the maximum number of attempts is 3. However you must write your program in such a way that these values are easily changed. (More about this below.)
After login into the system, your program will display a menu with the image processing choices shown below. Notice that after processing any choice but "Quit", your program will redisplay the menu
For those options requiring the "last picture displayed", keep in mind that you can have a "last picture" even though no images are being displayed at the moment on the screen. For example, you could have doubled a picture and cleared the screen, however you do have a last picture accessible via PictureUtil.getLastPicDisplayed().
Your screen should be cleared in the following situations:
There are two error conditions your program must handle:
〈option〉: there is no picture available.
where 〈option〉 is one of the options available to the user. 〈option〉 can assume any of the following values: "Double", "Inverse", "Add", "Posterize Inverse Double" and "Display Last". The processing of a particular image processing option will end once the above message has been generated. Notice that the program will not end.
The ImageProcessor class is the one you are to implement for this project. This class has several methods you must implement. One of them, the runProcessor() method, is the one that starts the image processing system. If you take a look at the Driver.java file you will notice that after creating an ImageProcessor object we call runProcessor in order to start the image processing system. The runProcessor method will call directly or indirectly other methods of the class. Keep in mind that methods of the ImageProcessor class may call each other as well. The parameter declarations, or signatures, of each method associated with the ImageProcessor class will be described next. Note that all of the methods except lastPictureExist() are to be declared as public methods.
Enter 1 to read new picture
Enter 2 to double last picture
Enter 3 to invert last picture
Enter 4 to add image to last picture
Enter 5 to posterize, double, invert last picture
Enter 6 to display original picture
Enter 7 to display last picture
Enter 8 to clear screen
Enter 9 to Quit
The method returns an integer value representing the user's choice.
The following is 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.
After starting the program and specifying the password
After selecting "OK" and entering 1 (one)
After selecting "OK" and entering image location
After selecting "OK" and entering 3
After selecting "OK" and entering 8
After selecting "OK" and entering 7
After selecting "OK" and entering 9
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. The best 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. Make sure that we are able to run your challenge problem by executing the Challenge.java file. To make this possible you must add a main method to the Challenge class which looks almost identical to the main method in Driver.java, except that instead of creating an ImageProcessor object you will be creating a Challenge object. Please make an entry in the time log indicating you have completed the challenge problem. Although the homework is considered an open homework, consider the Challenge Problem as a closed homework.
The challenge problem for this homework consists of adding an option to the program menu called "Random" (given as option number 10). The processing of this option has two parts: choose image to use and choose processing(s) to apply.
The "Random" option will choose randomly the image to use. It can choose between the last image displayed or it can ask the user for a new image. If there is no last image displayed, it will ask the user for a new image.
The "Random" option will then choose randomly which combination of image processings to apply. We have three basic image processings: posterize, double and invert. The "Random" option can choose to do any combination of them. For example, it can choose to just posterize, to double or invert, or to apply any two of the three, or to apply all the three. The result of the random processing is then displayed. (Hint: You can use a general Picture reference for storing the results of arbitrary operations.)
(Update Mon 10/04:) The above description states that the "Random" option performs either 1, 2 or all 3 of the operations. Some people have asked whether it is okay to offer 0 (zero) operations as one of the possibilities. The answer is yes, this is allowed but not required.
Submit your project using the submit project option associated with Eclipse. Remember to complete your time log before submitting your homework.