Ch. 2 - Programming Projects (Solutions) - 2
Ch. 2 - Programming Projects (Solutions) - 2
Disclaimer: In what follows, you will find the solutions to the exercises given in the 6th
edition of the book. If you happen to be using an earlier edition of the book, you should
match each one of the problems presented below to the proper exercise in the book that
you have. So keep in mind that the order in which the solutions are listed may not agree
with the order of the exercises in your book.
Please note that Secitons 2.7 (Graphics), 2.8 (Applets), and 2.9 (Drawing shapes) of
Chapter 2 are not required in the curriculum. Programming projects 2.12 to 2.20 (which
are marked in red) can be disregarded.
Chapter 2 Programming
Programming Projects Solutions
PP2.1 Create a revised version of the Lincoln application from Chapter 1 such
that quotes appear around the quotation.
PP2.2 Write an application that reads three integers and prints their average.
PP2.3 Write an application that reads two floating point numbers and prints their
sum, difference, and product.
PP2.5 Write an application that converts miles into kilometers (one mile equals
1.60935 kilometers). Read the miles value from the user as a floating point
value.
PP2.7 Create a version of the previous project that reserves the computation. That
is, read a value representing a number of seconds, then print the equivalent
amount of time as a combination of hours, minutes, and seconds (for
example, 9999 seconds is equivalent to 2 hours, 46 minutes and 39
seconds).
PP2.8 Write an application that determines the value of the coins in a jar and prints
the total in dollars and cents. Read the integer values that represent the
number of quarters, dimes, nickels, and pennies.
PP2.9 Write an application that prompts for an reads a double value representing a
monetary amount. Then determine the fewest number of each bill and coin
needed to represent that amount, starting with the highest (assume that a
ten dollar bill is the maximum size needed). For example, if the value
entered is 47.63 (forty-seven dollars and sixty-three cents), then the
program should print the equivalent amount as:
4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dime
0 nickels
3 pennies
PP2.10 Write an application that prompts for and reads an integer representing the
length of a square’s side, then prints the square’s perimeter and area.
PP2.11 Write an application that prompts for and reads the numerator and
denominator of a fraction as integers, then prints the decimal equivalent of
the fraction.
PP2.12 Create a revised version of the snowman applet with the following
modifications:
Add two buttons to the upper torso
Make the snowman frown instead of smile
Move the sun to the upper-right corner of the picture
Display your name in the upper-left corner of the picture
Shift the entire snowman 20 pixels to the right
PP2.13 Write an applet that writes your name using the drawstring method. Embed
a link to your applet in an HTML document and view it using a Web browser.
PP2.14 Write an applet that draws the Big Dipper. Add some extra stars in the night
sky.
PP2.15 Write an applet that drawns some balloons tied to strings. Make the balloons
of various colors.
PP2.16 Write an applet that draws the Olympics logo. The circles in the logo should
be colored, from left to right, blue, yellow, black, green, and red.
PP2.17 Write an applet that draws a house with a door (and doorknob), windows,
and a chimney. Add some smoke coming out of the chimney and some
clouds in the sky.
PP2.18 Write an applet that displays a business card of your own design. Iclude
both graphics and test.
PP2.19 Write an applet that displays your name in shadow text by drawing your
name in black, then drawing it again slightly offset in a lighter color.
PP2.20 Write an applet that shows a pie chart with eight equal sides all colored
differently.