600.108 Intro Programming Lab, Week 2

Getting Started: If your partner from last week's lab is present, please sit and work together again this week. Check with the lab leaders if you forget who your partner was, or if you need a (different) partner for this week for some reason. Start in opposite driver/navigator roles from last week if possible.

Do the posted Blackboard quiz. Your lab leaders will review the answers before you get started on this week's exercise.

This week we are going to use several phases to write a complete program from scratch. As we did last week, the first phase will still be analysis. However, we are going to skip the pseudocode phase. Instead, we will take an incremental coding approach with multiple phases of writing and testing parts of the solution (in Java). You will also need to make sure that your resulting program versions are fully checkstyle compliant at every step of development. (This may require updating the lab computer with the necessary plug-in jar and configuation files. If so, please consult the hw02 instructions for how to do this.)

The Problem: DESKTOP WALLPAPERING

I expect that most of us have customized a computer desktop with a favorite picture at some point. Digital pictures are represented as an array of pixels (picture elements), each with a color. Your computer screen has a resolution which tells you the width (number of columns) and height (number of rows), in pixels, that it uses to display things. Each digital image (picture file) also has a size, which is sometimes given in inches, and sometimes given in pixels. The pixel per inch (PPI) measurement of a digital image is the number of pixels corresponding to an inch (for example, if the picture were to be printed). A higher PPI leads to a better resolution, and the PPI is sometimes referred to as the density of the image.

The goal of this program is to calculate the specifics of two different display options for your chosen picture: centering and tiling. In both options the picture will be displayed in its actual size. When centering, the area around the picture will be filled with a solid color (like a mat when framing). When tiling, the picture will be repeated as many times as necessary so that the entire screen is filled. However, the last row and last column of tiles might only contain partial images depending on the measurements.

The input to the program must be

Using this data, your program will then compute and output:

You can assume (and should use test data such) that the screen size is larger than the picture size. You can prompt for the user to enter the input in any order and format that you like. Make sure your program is very user friendly. Include detailed prompts so that the user knows exactly what type of data to input, and nice descriptions on the output.

Step 1) ANALYSIS: First, use paper and pen to draw the problem in a way that makes sense to you. Make sure you understand the geometry and how to do the calculations for a solution. Remember to ask your lab leader if the problem needs clarification. Next, create two full sets of test data. This should include all the input values as well as the resulting output. You can do the calculations by hand or use the calculator accessory. Make up your data so that it demonstrates different situations. Show your samples to a lab leader before proceeding, and add your test data to the file on the display computer when approved.

--- Switch driver/nagivator roles ---

Step 2) CODING & TESTING: Write a program that prompts for all the input. Then add to the program so that it reads the width and height of the screen. Print the total area of the screen in square pixels. Compile and run your program several times to be sure it works. Also run the Checkstyle tool on it with our configuration file and make sure there are no issues. Resolve any problems, then compile and test your program again. Show it to a lab leader for approval to move on.

--- Switch driver/nagivator roles ---

Step 3) (more) CODING & TESTING: Add to the program so that it reads the size and resolution of the picture. Print the size of the picture in pixels. Then update the program so that it calculates and prints the total area surrounding the picture when centering is used. Compile and run your program several times to be sure it works, and make sure it is still checkstyle compliant. Show to a lab leader for approval to move on.

--- Switch driver/nagivator roles ---

Step 4) (even more) CODING & TESTING: Add to the program so that it calculates and prints the number of rows and columns when tiling is used. Remember to round up so that your output is whole numbers. As before, make sure your solution is checkstyle compliant before moving on.

--- Switch driver/nagivator roles ---

Step 5) (final) CODING & TESTING: Add to the program so that it calculates and displays the size of a picture (in inches) that would fill the whole screen. Compile and test. Lastly, add the computation of the screen size needed for an 8x10 at 1600 PPI. Once all the computations are correct, remove the extraneous output (the best way is to make those statements comments) and format the remaining data nicely. Make sure your code is still fully checkstyle compliant. Compile and run your program several times to be sure it works. Show to a lab leader for final approval.

Yay - you wrote several versions of a program from scratch!

Step 6) CLEAN-UP: Zip all the files together from today's lab and email to both students. Then each student must submit their work on Blackboard for the week, noting their partner's name and JHED login in the submission textbox. You must then delete your files off the lab computer and logout before leaving! Failure to do so constitutes an ethics violation.