Java Reference
In-Depth Information
*7.30
( Algebra: solve linear equations ) Write a method that solves the following
system of linear equations:
2
*
2
a 00 x
+
a 01 y
=
b 0
b 0 a 11 -
b 1 a 01
b 1 a 00 -
b 0 a 10
b 1
x
=
a 01 a 10
y
=
a 10 x
+
a 11 y
=
a 00 a 11 -
a 00 a 11 -
a 01 a 10
The method header is
public static double [] linearEquation( double [][] a, double [] b)
The method returns null if is 0 . Write a test program that
prompts the user to enter and and displays the result. If
is 0 , report that “The equation has no solution.” A sample run is
similar to Programming Exercise 3.3.
a 00 a 11 -
a 01 a 10
a 00 , a 01 , a 10 , a 11 , b 0 ,
b 1 ,
a 00 a 11 -
a 01 a 10
*7.31
( Geometry: intersecting point ) Write a method that returns the intersecting point of
two lines. The intersecting point of the two lines can be found by using the formula
shown in Programming Exercise 3.25. Assume that ( x1 , y1 ) and ( x2 , y2 ) are the
two points on line 1 and ( x3 , y3 ) and ( x4 , y4 ) are on line 2. The method header is
public static double [] getIntersectingPoint( double [][] points)
The points are stored in a 4-by-2 two-dimensional array points with
( points[0][0] , points[0][1] ) for ( x1 , y1 ). The method returns the intersect-
ing point or null if the two lines are parallel. Write a program that prompts the
user to enter four points and displays the intersecting point. See Programming
Exercise 3.25 for a sample run.
*7.32
( Geometry: area of a triangle ) Write a method that returns the area of a triangle
using the following header:
public static double getTriangleArea( double [][] points)
The points are stored in a 3-by-2 two-dimensional array points with
points[0][0] and points[0][1] for ( x1 , y1 ). The triangle area can be com-
puted using the formula in Programming Exercise 2.15. The method returns 0 if the
three points are on the same line. Write a program that prompts the user to enter
two lines and displays the intersecting point. Here is a sample run of the program:
Enter x1, y1, x2, y2, x3, y3:
The area of the triangle is 2.25
2.5 2 5 -1.0 4.0 2.0
2 2 4.5 4.5 6 6
Enter x1, y1, x2, y2, x3, y3:
The three points are on the same line
*7.33
( Geometry: polygon subareas ) A convex 4-vertex polygon is divided into four tri-
angles, as shown in Figure 7.9.
Write a program that prompts the user to enter the coordinates of four vertices and
displays the areas of the four triangles in increasing order. Here is a sample run:
Enter x1, y1, x2, y2, x3, y3, x4, y4:
-2.5 2 4 4 3 -2 -2 -3.5
The areas are 6.17 7.96 8.08 10.42
 
Search WWH ::




Custom Search