Java Reference
In-Depth Information
to print the remainder of each verse. Visit the website en.wikipedia.org/wiki/The_Twelve_Days_
of_Christmas_(song) for the lyrics of the song.
5.30 (Modified AutoPolicy Class) Modify class AutoPolicy in Fig. 5.11 to validate the two-letter
state codes for the northeast states. The codes are: CT for Connecticut, MA for Massachusetts, ME
for Maine, NH for New Hampshire, NJ for New Jersey, NY for New York, PA for Pennsylvania
and VT for Vermont. In AutoPolicy method setState , use the logical OR ( || ) operator
(Section 5.9) to create a compound condition in an if else statement that compares the method's
argument with each two-letter code. If the code is incorrect, the else part of the if else statement
should display an error message. In later chapters, you'll learn how to use exception handling to in-
dicate that a method received an invalid value.
Making a Difference
5.31 (Global Warming Facts Quiz) The controversial issue of global warming has been widely
publicized by the film “An Inconvenient Truth,” featuring former Vice President Al Gore. Mr. Gore
and a U.N. network of scientists, the Intergovernmental Panel on Climate Change, shared the 2007
Nobel Peace Prize in recognition of “their efforts to build up and disseminate greater knowledge
about man-made climate change.” Research both sides of the global warming issue online (you
might want to search for phrases like “global warming skeptics”). Create a five-question multiple-
choice quiz on global warming, each question having four possible answers (numbered 1-4). Be ob-
jective and try to fairly represent both sides of the issue. Next, write an application that administers
the quiz, calculates the number of correct answers (zero through five) and returns a message to the
user. If the user correctly answers five questions, print “Excellent”; if four, print “Very good”; if
three or fewer, print “Time to brush up on your knowledge of global warming,” and include a list
of some of the websites where you found your facts.
5.32 (Tax Plan Alternatives; The “FairTax”) There are many proposals to make taxation fairer.
Check out the FairTax initiative in the United States at www.fairtax.org . Research how the pro-
posed FairTax works. One suggestion is to eliminate income taxes and most other taxes in favor of
a 23% consumption tax on all products and services that you buy. Some FairTax opponents ques-
tion the 23% figure and say that because of the way the tax is calculated, it would be more accurate
to say the rate is 30%—check this carefully. Write a program that prompts the user to enter expenses
in various expense categories they have (e.g., housing, food, clothing, transportation, education,
health care, vacations), then prints the estimated FairTax that person would pay.
5.33 (Facebook User Base Growth) According to CNNMoney.com, Facebook hit one billion us-
ers in October 2012. Using the compound-growth technique you learned in Fig. 5.6 and assuming
its user base grows at a rate of 4% per month, how many months will it take for Facebook to grow
its user base to 1.5 billion users? How many months will it take for Facebook to grow its user base
to two billion users?
 
Search WWH ::




Custom Search