Line
Line
import java.util.*;
/**
* necessary instance variables are: Point1
* NULL POINTER EXCEPTION = RUN TIME ERROR
*/
public class Line
{
Point p1;//This variable stores a point
Point p2;//This variable stores a point
//Default constructor
public Line()
{
p1 = new Point();
p2 = new Point();
p1.y = 4;
p2.y = 4;
}
//Parameeterised constructor
public Line(Point p1 , Point p2)
{
this.p1 = p1;
this.p2 = p2;
}
return m == m2;
}
{
Scanner sc = new Scanner(System.in);
int option , start , reuse;
Point p1;
p1 = new Point();
Point p2;
p2 = new Point();
Line l2;
l2 = new Line();
Line l1;
l1 = new Line(p1 , p2);
switch (option)
{
case 1:
System.out.println("The Slope of the line is:" + l1.getSlope());
break;
case 2:
System.out.println("Enter the coordinates of another point in the
same line :");
Point p3;
p3 = new Point();
p3.readCoordinates();
System.out.print (l1.isCollinear(p3));
break;
case 3:
System.out.println("Enter the coordinates of the first point of
line 2:\t");
l2.p1.readCoordinates();
System.out.println("Enter the coordinates of the second point of
line 2:\t");
l2.p2.readCoordinates();
System.out.println(l1.isParallel(l2));
break;
case 4:
System.out.println("Enter the coordinates of the first point of
line 2:\t");
l2.p1.readCoordinates();
System.out.println("Enter the coordinates of the second point of
line 2:\t");
l2.p2.readCoordinates();
System.out.println(l1.isPerpendicular(l2));
File: Untitled Document 1 Page 3 of 3
break;
default:
System.out.println("Pls choose a correct option");// Break is not
required for case in the end
}
System.out.println("Enter 1 to use this data or else enter 0\t");
reuse = sc.nextInt();
}
System.out.println("Enter 1 to use the function and 0 to exit\t");
start = sc.nextInt();
}
/**
* Output:
*
* Enter 1 to use the function and 0 to exit1
Enter the coordinates of the first point of line 1:
Enter the coordinates of x axis 3
Enter the coordinates of y axis 5
Enter the coordinates of the second point of line 1:
Enter the coordinates of x axis 3
Enter the coordinates of y axis 8
Enter 1 to use this data or else enter 0 1
Enter 1. to use the slope function
Enter 2. to use is collinear function
Enter 3. to use is parallel function
Enter 4. to use is perpendicular function
1
The Slope of the line is:Infinity
Enter 1 to use this data or else enter 0
0
Enter 1 to use the function and 0 to exit
0
*/
}
}