Page 223 - Introduction to Programming with Java: A Problem Solving Approach
P. 223

                Summary
• Sun’s Java documentation identifies the public interface of all Java API software. It also provides a brief description of what it does and how to use it. The java.lang package is always available.
• The Math class provides methods that enable you to compute powers and roots, maximums or mini- mums, angle conversions, and many trigonometric functions. The random function generates a ran- dom number whose distribution is uniform in the range 0.0 to 0.9 repeating. This class also provides named constant values for PI and E.
• Numerical wrapper classes like Integer, Long, Float and Double contain parsing methods like parseInt that enable you to convert String representations of numbers into numerical format. MIN_VALUE and MAX_VALUE named constants give maximum and minimum allowable values for the various numerical data types.
• The Character class provides methods that tell you whether a character is whitespace, a digit, or let- ter, and if it’s a letter whether it’s lowercase or uppercase. Other methods allow you to change case.
• The String class’s indexOf method helps you find the position of a particular character in a string of text. The substring method allows you to extract any part of a given string of text. The replaceAll and replaceFirst methods make substitutions within a string of text. You can make case conversions with the toLowerCase and toUpperCase methods, and you can use the trim method to remove whitespace from either end of a string of text.
• The first argument in the System.out.printf method is a format string which enables you to use a
special code to specify the output format of text and numbers. For example, to display a double num-
System.out.printf("$%,04.2f\n", price);
• Use the Random class in the java.util package to get various random number distributions or ob- tain exactly the same list of random numbers every time you run a particular program.
• Use methods in Java API’s Graphics class to display photographic images, geometric figures, and text in graphics windows.
• To execute a Java applet, create an HTML file that specifies the Java applet, and load the HTML file within a Web browser.
Review Questions
§5.3 MathClass
1. Given these declarations:
double diameter = 3.0;
double perimeter;
Provide a statement that assigns the length of a circle’s perimeter to the perimeter variable. Use the
diameter variable.
2. What is the name of the class that contains the abs, min, and round methods?
a) Arithmetic b) Math
c) Number
Summary 189
 ber called price as dollars and cents with commas between groups of three digits and a zero to the left Apago PDF Enhancer
of the decimal for values less than $1.00, you would write:
  AU: We usually avoid having 1 line of text under a head.
—Comp








































































   221   222   223   224   225