Java Reference
In-Depth Information
Enter the exchange rate from dollars to RMB: 6.81
Enter 0 to convert dollars to RMB and 1 vice versa: 5
Incorrect input
*3.32
( Geometry: point position ) Given a directed line from point p0(x0, y0) to p1(x1,
y1), you can use the following condition to decide whether a point p2(x2, y2) is
on the left of the line, on the right, or on the same line (see FigureĀ 3.11):
7
0 p2 is on the left side of the line
(x1
-
x0)*(y2
-
y0)
-
(x2
-
x0)*(y1
-
y0)
c
=
0p2isonthesameline
6
0 p2 is on the right side of the line
p 1
p 1
p 1
p 2
p 2
p 2
p 0
p 0
p 0
(a)
(b)
(c)
F IGURE 3.11
(a) p2 is on the left of the line. (b) p2 is on the right of the line. (c) p2 is on
the same line.
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, on the right, or on
the same line. Here are some sample runs:
Enter three points for p0, p1, and p2: 4.4 2 6.5 9.5 -5 4
(-5.0, 4.0) is on the left side of the line from (4.4, 2.0) to (6.5, 9.5)
Enter three points for p0, p1, and p2: 1 1 5 5 2 2
(2.0, 2.0) is on the line from (1.0, 1.0) to (5.0, 5.0)
Enter three points for p0, p1, and p2: 3.4 2 6.5 9.5 5 2.5
(5.0, 2.5) is on the right side of the line from (3.4, 2.0) to (6.5, 9.5)
*3.33
( Financial: compare costs ) Suppose you shop for rice in two different packages.
You would like to write a program to compare the cost. The program prompts the
user to enter the weight and price of the each package and displays the one with
the better price. Here is a sample run:
Enter weight and price for package 1: 50 24.59
Enter weight and price for package 2: 25 11.99
Package 2 has a better price.
 
 
Search WWH ::




Custom Search