source file name: ActionPoints.java
import java.io.*;
class Points
{
int x1,x2,y1,y2;
public Points(int p,int q,int r,int s)
{
x1=p;y1=q;x2=r;y2=s;
}
public void disppoints()
{
System.out.println("x1: "+x1+" y1= "+y1);
System.out.println("x2: "+x2+" y2= "+y2);
}
public void length()
{
double len;
len=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
System.out.println("length of segment QP is = "+len);
}
public void slope()
{
double len;
len=(y2-y1)/(x2-x1);
System.out.println("slope of segment QP is ="+len);
}
}
class ActionPoints
{
public static void main(String as[])
{
Points p1=new Points(10,10,11,11);
p1.disppoints();
p1.length();
p1.slope();
Points p2=new Points(10,-5,16,10);
p2.disppoints();
p2.length();
p2.slope();
}
}
output:
D:\JavaPrograms\Constructors>javac ActionPoints.java
D:\JavaPrograms\Constructors>java ActionPoints
x1: 10 y1= 10
x2: 11 y2= 11
length of segment QP is = 1.4142135623730951
slope of segment QP is =1.0
x1: 10 y1= -5
x2: 16 y2= 10
length of segment QP is = 16.15549442140351
slope of segment QP is =2.0
0 Comments
Post a Comment