Programming Exercise 6.39 gives a method for testing whether three points are on the same line.Write the

Question:

Programming Exercise 6.39 gives a method for testing whether three points are on the same line.Write the following method to test whether all the points in the array points are on the same line.public static boolean?sameLine(double[][] points)Write a program that prompts the user to enter five points and displays whether they are on the same line. Here are sample runs:image

Exercise 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:

image

image

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):

image

image

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:

image

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question
Question Posted: