Java Reference
In-Depth Information
returns the string representation for the number. For example, format(34, 1)
returns 34 .
Write a test program that prompts the user to enter a number and its width and
displays a string returned by invoking format(number, width) .
*6.38
( Generate random characters ) Use the methods in RandomCharacter in Listing
6.10 to print 100 uppercase letters and then 100 single digits, printing ten per line.
6.39
( Geometry: point position ) Programming Exercise 3.32 shows how to test whether
a point is on the left side of a directed line, on the right, or on the same line. Write
the methods with the following headers:
/** Return true if point (x2, y2) is on the left side of the
* directed line from (x0, y0) to (x1, y1) */
public static boolean leftOfTheLine( double x0, double y0,
double x1, double y1, double x2, double y2)
/** Return true if point (x2, y2) is on the same
* line from (x0, y0) to (x1, y1) */
public static boolean onTheSameLine( double x0, double y0,
double x1, double y1, double x2, double y2)
/** Return true if point (x2, y2) is on the
* line segment from (x0, y0) to (x1, y1) */
public static boolean onTheLineSegment( double x0, double y0,
double x1, double y1, double x2, double y2)
Write a program that prompts the user to enter the three points for p0 , p1 , and p2
and displays whether p2 is on the left of the line from p0 to p1 , right, the same
line, or on the line segment. Here are some sample runs:
Enter three points for p0, p1, and p2: 1 1 2 2 1.5 1.5
(1.5, 1.5) is on the line segment from (1.0, 1.0) to (2.0, 2.0)
Enter three points for p0, p1, and p2: 1 1 2 2 3 3
(3.0, 3.0) is on the same line from (1.0, 1.0) to (2.0, 2.0)
Enter three points for p0, p1, and p2: 1 1 2 2 1 1.5
(1.0, 1.5) is on the left side of the line
from (1.0, 1.0) to (2.0, 2.0)
Enter three points for p0, p1, and p2: 1 1 2 2 1 -1
(1.0, -1.0) is on the right side of the line
from (1.0, 1.0) to (2.0, 2.0)
 
 
Search WWH ::




Custom Search