CS 101 - Intro to Computing, Spring 2011

Lab 9

Due: Thursday 10/27/2011 by 11:59 pm

For this lab assignment, you are to take an image and create a new image that will show multiple instances of the images stacked one on top of another.

The program in Lect1020d.java may be useful in completing this project. This code repeats part of a picture horizontally two times.

For this lab, you must complete the following:

  1. Prompt the user for a number that will determine the number of times the image gets duplicated.

    To get the user's input, we will use the getIntNumber() method of the SimpleInput class. The SimpleInput class is one of the classes in the bookCAlasses directory. This method will display a "pop-up" window that will prompt the user to enter an integer value.

    The getIntNumber() has two ways it can be used. In either way, it takes a String parameter will be displayed as a message when the user is prompted for the input. That is the only parameter for the first way that getIntNumber() can be used. The other way also takes two more parameter which specify the range the number enter by the user must be in. The following code shows both of these ways.

    // declare in integer variable to store the number entered by the user.
    int value;
    
    // prompt the user for the number
    value = SimpleInput.getIntNumber ("Please enter an integer value.");
    
    // display the value entered by the user
    System.out.println ("The user entered: " + value);
    
    // prompt the user for a number within a range of values
    value = SimpleInput.getIntNumber ("Please enter an integer value between 1 and 10.", 1, 10);
    
    // display the value entered by the user
    System.out.println ("The user entered: " + value);
    

    For this lab, you can use either form of the getIntNumber() method that you want. If probably makes sense to use second version of the method. The lower number in the range should be one. Values less than one don't really make any sense. (Perhaps the value of zero could make sense, if you wanted to run the program that didn't create any duplicates of the image. But then why run the program at all?) The upper number in the range could be somewhere around 10, because creating more than 10 duplicates would make the final image quite large.

  2. Your program must prompt the user for the image file to use.

  3. Your program is to duplicate the image the number of times indicated by the integer value given by the user. If we used the flower image, entering the value of 1 would give us:

    Entering the value of 2 would give us:

    Entering the value of 3 would give us:

    Since we are stacking the duplicate images one on top of the next, the width of the new image will be the same as the original image. The height of the new image will be the result of multiplying the height of the original image by the number of duplications we want to create. Thus if the original image had height of 250, the resulting image with 1 duplication would have height of 250 (250 x 1). The resulting image with 2 duplications would have height of 500 (250 x 2). The resulting image with 3 duplications would have height of 750 (250 x 3). The resulting image with 4 duplications would have height of 1000 (250 x 4).

    As we copy the images onto the resulting canvas, we must make sure the Y coordinate of the resulting image would equal to the Y coordinate of the original pixel plus (the height of the image multiplied by a value specifying which copy is being created.

    Your code should add one more NESTED loop to the code used during lectures:

    The new Y coordinate would need to use the loop counter of this NESTED loop to determine where the pixel needs to go in the final picture.

  4. Your program must prompt the user for another filename in which the resulting is to be stored.

  5. Be sure to include a comment at the top of your program containing the following information:

How assignments should be submitted

You are to submit your program electronically using the link for Lab 9 on the Assignments Page in Blackboard.