Homework #3 CMSC 131
Due Friday Feb 25, 6:00 pm Object-Oriented Programming I
Type of homework: Open Spring 2005

Objective

In this homework you will practice defining methods for classes.

Overview

For this assignment you will implement a class called ImageSystem that provides support for several picture processing options. (You will need to generate an ImageSystem.java file that contains your ImageSystem class.)  As part of the code distribution we have provided a Driver class that relies on the ImageSystem class  This driver implements a simple GUI (Graphical User Interface) allowing users to request picture manipulations like converting an image to a black and white image, placing two images side by side, etc.  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 some of the methods you will implement and a time log.

This homework will be graded as follows:

Specifications

Code Distribution

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 time log file, a pseudocode file, a Challenge.java file, and two jpeg images.

Most of the classes in the picture library are from the previous homework. One new class is Posterize.   This class creates a picture object that "posterizes" an input picture. Posterizing is the process of replacing the colors of the image with a very limited set of colors. The result has a cartoonish look. The original image is given as a parameter when creating this object.

Two important methods you must be aware for this project are PictureUtil.anyPicDisplayed() and PictureUtil.getLastPicDisplayed(). The first method returns a boolean indicating whether or not any pictures have already 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. (Note: If there is no last image, a null reference is returned.) Here is an example:

    Picture p = PictureUtil.getLastPicDisplayed();
    PictureUtilShow(p);

You will run the image processing application  program by executing the main() method of the Driver class. Note: The driver creates an instance of the ImageSystem class which provides all the image processing support.

Processing

The Driver class we have provided makes use of the class you are expected to implement.  The purpose of the driver is to help you understand the functionality associated with the ImageSystem class methods.  You may not modify the Driver class.   

The driver's processing can be subdivided in two parts: (1) login into the image processing system; and (2) process 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. The driver defines as valid passwords "cmsc131" and "CS1".  The maximum number of attempts is three.

After the user logs into the system, the driver will display a menu with the image processing choices shown below. Note: After processing any choice but "Quit", the driver redisplays the menu.

For the option 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.

ImageSystem Methods

Your main task for this project is to implement the ImageSystem class.  A description of each method you must implement follows. 

Public Methods

This method has three parameters, two String references and an integer. The String parameters represent the two valid passwords.  The integer parameter represents the maximum number of attempts allowed during the password reading process.  This method will prompt the user to enter a password value using a dialog box that displays the message "Enter password". The user has the given maximum number of attempts to provide the correct password.  The method returns the boolean value true if the user provides any of the expected passwords and false if the user has not provided a correct password after exhausting the maximum number of attempts.  The message "Invalid password" should be displayed in a dialog box for each failed attempt.

This method will prompt the user to enter an image's location using a dialog box that displays the message "Enter image location".  The method will create an Image object based on the provided location and return a reference to that object.

The processing that takes place depends on the option parameter.  The parameter can assume the values:

    "ProvidedPicture" - Displays the provided picture.

    "LastPicture" -  Ignores the picture parameter and redisplays the last picture.

    "ClearScreen" - Ignores the picture parameter and clears the screen.

The processing that takes place depends on the processing parameter.  The parameter can assume the values:

    "BlackAndWhite" - The picture is converted to a black and white picture and a reference to the new picture object is returned.  The options parameter is ignored.

 

    "Posterize" - The picture parameter is posterized and a reference to the new picture object is returned. The options parameter is ignored.

 

    "SelectComponents" - A new picture object will be created with only the color components specified in the options parameters.  The processPicture method relies on the private method selectComponents (not to be confused with the SelectComponents Class) to process the color selection (see selectComponents description below).

The processing that takes place depends on the processing parameter.  The parameter can assume the values:

   

     "CombineTopBottom" - Combines the two images one on top of the other.  The first image is the top and the second image is the bottom.  The options parameter is ignored.

 

    "CombineLeftRight" - Combines the two images side by side.  The first image goes on the left and the second image on the right.  The options parameter is ignored.

 

    "Mosaic" - A new picture object representing a mosaic will be created. The processPictures method relies on the private method createMosaic to generate the new picture (see mosaic description below). The options parameter represents the color components to use for the generation of the mosaic.

Private Methods

This method creates a new picture object by using the SelectComponents class you used in the previous project. (Click here for a description of the SelectComponents class in homework 2).  The colors parameter identifies which components will be present in the new picture.  This string can be any combination of the following characters: 'R' , 'r' , 'G', 'g ', 'B', 'b'.  For example, the string "RB" indicates we want a picture with only red and blue components. The string "gb" indicates we only want the green and blue components.  The following are examples of valid colors strings:

                 "RGB"    "rgb"    "RgB"    "BRG"    "br"    "g"    "r"    ""    "RgBbG"    "RGbBb"

As you can see multiple instances of the same character (either upper case or lowercase or both) can be part of the string.  For example in "RBGb", characters 'B' and 'b' appear in the string.  After 'B' is seen it is understood the blue component is required so any successive 'B' or 'b' is ignored (i.e., it has no effect on the color components selection process).  An empty string means no colors components are selected.  

This method creates a mosaic. We define a mosaic as a picture composed of four images. Two of the pictures are the picture parameters. The third picture (let's call it pictureThree) is generated by selecting color components from pictureOne.  The fourth picture (let's call it pictureFour) is generated by selecting color components from pictureTwo.  The colors parameter defines which color components to use for both pictures.  The format associated with the colors parameter is the same one used by the selectComponents method above.  The mosaic picture is the result of combining the pictures so that pictureOne and pictureThree are side by side and on top of pictureFour and pictureTwo (which at the same time are side by side).  The following diagram illustrates the pictures' arrangement.

pictureOne

pictureThree

pictureFour

pictureTwo

 

Requirements

Sample Run

The following is a sample run of the Driver class that relies on the ImageSystem class you must implement.

After starting the program and specifying the wrong password


After selecting "OK"

 


After selecting "OK" and entering valid password

 


After selecting "OK" and selecting 1

 

 


After selecting "OK" and entering image location

 


After selecting "OK" and entering 5


After selecting "OK" and entering image location

 


After selecting "OK" and entering 3

 


After selecting "OK" and entering 9


After selecting "OK" and entering image location


After selecting "OK" and entering image location


After selecting "OK" and entering bR


After selecting "OK" and entering 10


After selecting "OK" program terminates.


Challenge Problem

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

The challenge problem for this homework consists of adding new processing alternatives to the processPictures method of the ImageSystem class.   The project defines "CombineTopBottom", "CombineLeftRight" and "Mosaic" as the possible alternatives for this method.  You could add any of the following alternatives for the corresponding number of gold stars.

One Gold Star  - Option name "MosaicComplement"

    Create a mosaic where pictureThree (see mosaic description) uses the color components defined by the options parameter, but pictureFour (see mosaic description) uses the complement of those colors.  For example, if options is "R" then you will use "GB" for pictureFour.

Two Gold Stars  - Option name "MosaicRandom"

    Create a mosaic with the same kind of pictures generated by "Mosaic", but where the pictures are randomly placed in the different quadrants.

Three Gold Stars  - Option name "MosaicRandomProcessings"

    Create a four-picture mosaic based on the parameter pictures, where parameter pictures are processed using alternatives associated with processPicture (the single image processing method).  Randomly select which processings to apply.  For the SelectComponents option randomize which color components to select.

IMPORTANT: If you decide to complete the challenge problem then:   

Although the homework is considered an open homework, consider the Challenge Problem as a closed homework.


Submission

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


Web Accessibility