Java Reference
In-Depth Information
13 What's My Color
Write an applet that allows the user to enter three positive integers between 0
and 255, each of which corresponds to a specified red, green, and blue color.
Then, when the user clicks a Button object, the background color of the applet
changes to match the color created by the red, green, and blue colors. Invalid
numbers, less than zero or greater than 255, should display error messages.
14 Formatting Output
Write an application that accepts a double number and then displays it in five
different ways, using a combination of dollar signs, thousands separators, deci-
mal places, and other formats. Use the Java API to look up DecimalFormat and
discover some formatting patterns that were not covered in this chapter. Use at
least two patterns from the API.
J ava 2
J ava 2
v 5 . 0
15 Using the API
v 5 . 0
The printf() method, new to J2SE Version 5.0, uses several special characters
to provide formatted output based on data types, similar to the C++
programming language. Visit the Sun Microsystems Java API Web site at
http://java.sun.com/j2se/1.5.0/docs/api/io/PrintStream.html. Use the index to
find the printf() method. Click the link, Format string Syntax. Scroll to display
the conversion characters, flags, and their definitions. Using a word processing
program, create a table with three columns that lists each character or flag, its
definition in your own words, and a sample usage or code. Print the table and
turn it in to your instructor.
Java 2
Java 2
v 5 . 0
16 Using the printf() Method
v 5 . 0
In Programming Assignment 6, you created an application to calculate traffic
violation charges. Convert the program to use the J2SE 5.0 printf() method.
Use dialog boxes for input, but convert all output to display in the console using
forms of the printf() method. Table 4-12 on page 262 displays the various special
characters used in the format string to embed data within the output rather than
concatenating it to display in a dialog box.
Search WWH ::




Custom Search