You are on page 1of 2

CSCE A201, Fall 2017

Assignment 3
Due 5 Oct 2017 by 11:59pm to Blackboard
10 points each (20 points total)

Complete the following programming problems using a separate class and file for each. For all
programing assignments, be sure to use good style and documentation. See the
DocumetationAndStyle.pdf file on Blackboard. For the programming assignments, style and
documentation points are worth 10% of the point total and are awarded independent of the
correct functioning of your program. When complete, please zip your .java files (complete
project directory if you are using NetBeans) together and upload to Blackboard.

1. Bouncing ball. Simulate a bouncing ball by computing its height in feet at each second as
time passes on a simulated clock. Begin the ball at time zero and height zero. Prompt the
user to enter an initial velocity for the ball in feet/second. Check for invalid entries by the
user (e.g. the velocity must be a positive integer) and continue to prompt the user until a valid
velocity is entered.

Recall that gravity exerts a downward force of 32 ft/sec2, so after each second, change the
height by adding the current velocity. To simulate a bounce, if the new height is less than
zero, multiply both the height and velocity by -0.5. Once you have checked for a bounce,
apply gravity by subtracting 32 from the velocity. Terminate the program at the 5th bounce
(print at least Bounce 5, optionally print Time & Height after Bounce 5). Before
beginning this problem, be sure to write your algorithm in pseudocode.

Example output:
Enter the initial velocity of the ball: 100
Time: 0 Height: 0.0
Time: 1 Height: 100.0
Time: 2 Height: 168.0
Time: 3 Height: 204.0
Time: 4 Height: 208.0
Time: 5 Height: 180.0
Time: 6 Height: 120.0
Time: 7 Height: 28.0
Bounce 1
Time: 8 Height: 48.0
Time: 9 Height: 78.0
Time: 10 Height: 76.0
Time: 11 Height: 42.0
Bounce 2
...
2. Red-eye reduction. The below image is from an article by HP Labs, entitled "Beyond Film"
at http://www.hpl.hp.com/news/2004/apr-jun/beyond_film.html . The article discusses
techniques for automatic red-eye reduction from photographs. Use the copy of this image on
Blackboard, redeye_image.jpg, and the example code in ShowImage.java to
complete this assignment.

Write a program that finds the red pixels in both eyes and sets the red component to the
average of the green and the blue components. This turns the red pixel into a corresponding
shade of gray. For example, if a pixel is (R=160, G=20, B=30), then the red component
should be set to (20+30)/2 or 25. The pixel should then be changed into (R=25, G=20,
B=30). To determine appropriate thresholds for which pixels to change, use an image
manipulation program like Paint on Windows (select a pixel with the Color picker tool and
then click Edit colors to see the RGB values. Remember that having a strong red component
does not necessarily mean the pixel will be red (e.g. yellow = 255,255,0).

If you change every pixel in the image according to this rule then most of the flesh tones and
the lips of the subject would also be changed to gray. Therefore, you should only process
pixels in the region around the red eyes. To help you out, here are the coordinates of
rectangles that capture each eye. Your program only needs to process pixels within the inside
of these rectangles.

You might also like