Exercises
Exercise 8-1. Several internationalization-related classes, such as
NumberFormat
andDateFormat
, have static methods namedgetAvailableLocales( )
that return an array of theLocale
objects they support. You can look up the name of the country of a givenLocale
object with thegetDisplayCountry( )
method. Note that this method has two variants. One takes no arguments and displays the country name as appropriate in the default locale. The other version ofgetDisplayCountry( )
expects aLocale
argument and displays the country name in the language of the specified locale.Write a program that displays the country names for all locales returned by
NumberFormat.getAvailableLocales( )
. Using the static locale constants defined by theLocale
class, display each country name in English, French, German, and Italian.Exercise 8-2. Modify the
Portfolio
class of Example 8-3 to remove all hardcoded display strings. Instead, use theResourceBundle
andMessageFormat
classes as demonstrated in Examples Example 8-4 and Example 8-5.Exercise 8-3. Write a multicity digital clock program that displays the current date and time in the cities Washington, London, Paris, Bonn, Beijing, and Tokyo. Display the dates and times using the customary formats for those cities. You’ll want to read about the
java.util.TimeZone
class and theDateFormat.setTimeZone( )
method. Consult a map or search the Internet to determine the time zones for each of the cities. Write the program as an AWT or Swing application ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.