Question: Vertical Lines The program should avoid a divide by zero error by checking for vertical lines. In a vertical line: x 2 = x 1

Vertical Lines
The program should avoid a divide by zero error by checking for vertical lines. In a
vertical line: x2= x1; consequently: x2 x1=0.
Note: If one of the lines is found to be vertical/horizontal, all the program needs to do is
check to see if the other line is horizontal/vertical to determine whether they are
perpendicular or not.
Output
The program output should be either:
Lines are perpendicular
Or
Lines are not perpendicularInstructions
Write a Java program to determine whether two straight lines are perpendicular. The
program must prompt the user for the values of x-y coordinates for two points of each
line. Coordinate figures must be read as integers.
Example: in the graph below, the line AB is defined by the pairs: (15,10) and (49,25);
whereas the line CD is defined by (29,5) and (32,32).
Premises
For a line represented by two points: (x1,y1) and (x2,y2), the slope of such line,
m , is determined by:
m=y2-y1x2-x1
Given two lines with slopes m 1 and m 2 respectively, the lines are perpendicular if
the product of their slopes yields -1 :
(m1)(m2)=-1
Vertical Lines The program should avoid a divide

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!