You are on page 1of 3

6th Edition, Java Software Solutions

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.

Refer to Lincoln4.java in the folder named “chap02 pp solutions”.

PP2.2 Write an application that reads three integers and prints their average.

Refer to AverageOfThree.java in the folder named “chap02 pp solutions”.

PP2.3 Write an application that reads two floating point numbers and prints their
sum, difference, and product.

Refer to FloatCalculations.java in the folder named “chap02 pp solutions”.

PP2.4 Create a version of the TempConverter application to convert from


Fahrenheit to Celsius. Read the Fahrenheit temperature from the user.

Refer to TempConverter2.java in the folder named “chap02 pp solutions”.

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.

Refer to MilesToKilometers.java in the folder named “chap02 pp solutions”.

PP2.6 Write an application that reads values representing a time duration in


hours; minutes, and seconds, and then prints the equivalent total number
of seconds (for example, 1 hour, 28 minutes, and 42 seconds is equivalent
to 5322 seconds).

Refer to Seconds.java in the folder named “chap02 pp solutions”.


6th Edition, Java Software Solutions

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).

Refer to Seconds2.java in the folder named “chap02 pp solutions”.

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.

Refer to ChangeCounter.java in the folder named “chap02 pp solutions”.

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

Refer to MoneyConversion.java in the folder named “chap02 pp solutions”.

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.

Refer to SquareCalculations.java in the folder named “chap02 pp solutions”.

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.

Refere to Fraction.java in the folder named “chap02 pp solutions”.

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

Refer to Snowman2.java and Snowman2.html.


6th Edition, Java Software Solutions

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.

Refer to DrawName.java and DrawName.html.

PP2.14 Write an applet that draws the Big Dipper. Add some extra stars in the night
sky.

Refer to BigDipper.java and BigDipper.html.

PP2.15 Write an applet that drawns some balloons tied to strings. Make the balloons
of various colors.

Refer to Balloons.java and Ballons.html.

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.

Refer to OlympicRings.java and OlympicRings.html.

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.

Refer to HousePicture.java and HousePicture.html.

PP2.18 Write an applet that displays a business card of your own design. Iclude
both graphics and test.

Refer to BusinessCard.java and BusinessCard.html.

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.

Refer to ShadowName.java and ShadowName.html.

PP2.20 Write an applet that shows a pie chart with eight equal sides all colored
differently.

Refer to PieChart.java and PieChart.html.

You might also like