Java Programming with Joyce Ferall Book

Book Download

Free PDF Download: Java Programming in PDF written by Joyce Farrell

Chapter 01 Excercise:

Programming Exercise Chapter 01

Question StatementsCode
Write, compile, and test a class that displays your favorite movie quote on the screen. Save the class as MovieQuote.javaClick
Write, compile, and test a class that displays your favorite movie quote, the movie it comes from, the character who said it, and the year of the movie. Save the class as MovieQuoteInfo.java.Click
Write, compile, and test a class that displays the following pattern on the screen:Click
Write, compile, and test a class that displays at least four lines of your favorite song.
Save the class as FavoriteSong.java
Click
Write, compile, and test a class that uses the command window to display the
the following statement about comments:
Click
“Program comments are nonexecuting statements you add to a file for the purpose of
documentation.” Also include the same statement in three different comments in the class; each comment should use one of the three different methods of including comments in a Java class. Save the class as Comments.java.
Click
“Program comments are nonexecuting statements you add to a file for the purpose of
documentation.” Also, include the same statement in three different comments in the class; each comment should use one of the three different methods of including comments in a Java class. Save the class as Comments.java.
Click
Modify the Comments.java program in Exercise 10 so that the statement about comments is displayed in a dialog box. Save the class as CommentsDialog.java.Click
Shaving brushes You’ll soon see ’em On a shelf In some museum Burma Shave Find a classic Burma Shave rhyme on the Web. Write, compile, and test a class that produces a series of four dialog boxes so that each displays one line of a Burma Shave slogan in turn. Save the class as BurmaShave.javaClick
Chapter 01 ExercisesCodes

Game Zone

Write a Java application that displays two dialog boxes in sequence. The first asks you to think of a number between 1 and 10. The second displays a randomly generated number; the user can see whether his or her guess was accurate.

Case problem :

Carly’s Catering provides meals for parties and special events. Write a program that displays Carly’s motto, which is “Carly’s makes the food that makes it a party.” Save the file as CarlysMotto.java. Create a second program that displays the motto surrounded by a border composed of asterisks. Save the file as CarlysMotto2.java.

Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach
chairs, and umbrellas to tourists. Write a program that displays Sammy’s motto,
which is “Sammy makes it fun in the sun.” Save the file as SammysMotto.java.
Create a second program that displays the motto surrounded by a border
composed of repeated Ss. Save the file as SammysMotto2.java.

Chapter 02 Exercise:

Question StatementsCode
A. Write a Java class that declares a named constant to hold the number of quarts in a gallon (4). Also declare a variable to represent the number of quarts needed for a painting job, and assign an appropriate value—for example, 18. Compute and display the number of gallons and quarts needed for the job. Display explanatory text with the values—for example, A job that needs 18 quarts requires 4 gallons plus 2 quarts. Save the class as QuartsToGallons. java.
B. Convert the QuartsToGallons class to an interactive application. Instead of assigning a value to the number of quarts, accept the value from the user as input. Save the revised class as QuartsToGallonsInteractive.java.
6. (a). Write a class that declares a variable named inches, which holds a length in inches, and assign a value. Display the value in feet and inches; for example, 86 inches becomes 7 feet and 2 inches. Be sure to use a named constant where appropriate. Save the class as InchesToFeet.jav.
6.(b). Write an interactive version of the InchesToFeet class that accepts the inches value from a user. Save the class as InchesToFeetInteractive.java.
Click

6. (a). Write a class that declares a variable named inches, which holds a length in inches, and assign a value. Display the value in feet and inches; for example, 86 inches becomes 7 feet and 2 inches. Be sure to use a named constant where appropriate. Save the class as InchesToFeet.jav.
Click

6.(b). Write an interactive version of the InchesToFeet class that accepts the inches value from a user. Save the class as InchesToFeetInteractive.java.
Click
Q.7. Write a class that declares variables to hold your three initials. Display the three
initials with a period following each one, as in J.M.F. Save the class as Initials.java.

Click
Q.8. Meadowdale Dairy Farm sells organic brown eggs to local customers. They charge
$3.25 for a dozen eggs, or 45 cents for individual eggs that are not part of a dozen.
Write a class that prompts a user for the number of eggs in the order and then display
the amount owed with a full explanation. For example, typical output might be, “You
ordered 27 eggs. That’s 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each
for a total of $7.85.” Save the class as Eggs.java.
Click
Chapter 02 ExercisesCodes