6. |
P5. Comparing Visual and Numerical Information
Write a program that draws three lines, as in the following figure.

When the program starts, it should ask the user for a value v, then it draws the line joining the origin (0,0) with the point (v, 200).
Line2D.Double line1 = new Line2D.Double(0, 0, v, 200);
Note that the equation of this line is
y = x * 200 / v
The second (horizontal) line has the equation
x = 100
You can generate it by using the following:
Line2D.Double line2 = new Line2D.Double(100, 0, 100, getWidth());
The third (vertical) line has the equation
y = 100
Mark the intersection points with small circles and print their coordinate values. To compute the intersection points, you need to solve two sets of equations. This set gives you the first intersection point:
y = x * 200 / v x = 100
This set gives you the second intersection point:
y = x * 200 / v y = 100
Tip: Start with the Intersect.java program from the textbook. The code for drawing and labeling the intersection points is helpful. You will need to change the equations.
Answer:
|