Java Reference
In-Depth Information
*8.30
( Algebra: solve linear equations ) Write a method that solves the following
2
*
2 system of linear equations:
+
=
b 0 a 11
-
b 1 a 01
b 1 a 00
-
b 0 a 10
a 00 x
a 01 y
b 0
=
=
x
y
+
=
a 00 a 11
-
a 01 a 10
a 00 a 11
-
a 01 a 10
a 10 x
a 11 y
b 1
The method header is
public static double [] linearEquation( double [][] a, double [] b)
The method returns null if a 00 a 11
a 01 a 10 is 0 . Write a test program that
prompts the user to enter a 00 , a 01 , a 10 , a 11 , b 0 , and b 1 , and displays the result. If
a 00 a 11
-
a 01 a 10 is 0 , report that “The equation has no solution.” A sample run is
similar to Programming Exercise 3.3.
-
*8.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 inter-
secting 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 Program-
ming Exercise 3.25 for a sample run.
*8.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 computed using the
formula in Programming Exercise 2.19. The method returns 0 if the three points
are on the same line. Write a program that prompts the user to enter three points of
a triangle and displays the triangle's area. Here is a sample run of the program:
Enter x1, y1, x2, y2, x3, y3: 2.5 2 5 -1.0 4.0 2.0
The area of the triangle is 2.25
Enter x1, y1, x2, y2, x3, y3: 2 2 4.5 4.5 6 6
The three points are on the same line
*8.33
( Geometry: polygon subareas ) A convex 4-vertex polygon is divided into four
triangles, as shown in Figure 8.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