CS 1401, Quiz 8

Date: Tuesday, March 11, 2008
Name (please type legibly, ideally in block letters): ______________________________________________________________________
1. Mark what is covered and what is not covered in Chapter 8:

2-4. On March 11, 1702, the first regular English-language newspaper started its publication in London, England. Nowadays, almost all newspapers are computer-based. For example, computers decide how much you should pay for a newspaper ad. Let us assume that the price of the ad is equal to the price per square inch times the area of the ad (i.e., its width times height). For example, if a cost per square inch is $2.00, and the ad is 4.0 x 5.0 inches, then it should cost $2.00 X (4.0 X 5.0) = $40.00.

2. Write a method named priceOfAd that, given the price per square inch, width, and height, returns the overall price of the ad.

3. Call your method priceOfAd in the main method to compute the payment for an ad about a CS talk at a paper that charges $2 per square inch; the ad is 4 inches wide and 5 inches high. (You do not need to write the entire main method, just the part that assigns the corresponding value to the variable howMuch and calls your method.)

4. Trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct (should be $40).