Beginning Programming with Java For Dummies by Barry Burd

Beginning Programming with Java For Dummies by Barry Burd

Author:Barry Burd
Language: eng
Format: epub, pdf
Publisher: John Wiley & Sons, Ltd.
Published: 2012-03-11T16:00:00+00:00


Figure 10-2: Admission prices for Beginning Programming with Java For Dummies: The Movie.

The first if statement’s condition tests for the regular price group. Anyone who’s at least 12 years of age and is under 65 belongs in this group.

The second if statement’s condition tests for the fringe ages. A person who’s under 12 or is 65 or older belongs in this category.

When you form the opposite of an existing condition, you can often follow the pattern in Listing 10-1. The opposite of >= is <. The opposite of < is >=. The opposite of && is ||.

If you change the dollar amounts in Listing 10-1, you can get into trouble. For example, with the statement price = 5.00, the program displays Please pay $5.0. Enjoy the show! This happens because Java doesn’t store the two zeros to the right of the decimal point (and Java doesn’t know or care that 5.00 is a dollar amount). To fix this kind of thing, see the discussion of NumberFormat.getCurrencyInstance in Chapter 18.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.