source file name: ActionPoint.java
import java.io.*;
class Point
{
int x,y;
public Point(int p,int q)
{
x=p;y=q;
}
public Point()
{
x=0;y=0;
}
public void disppoint()
{
System.out.println("x: "+x+" y= "+y);
}
public void length(Point O,Point P)
{
double len;
len=Math.sqrt((P.x-O.x)*(P.x-O.x)+(P.y-O.y)*(P.y-O.y));
System.out.println("length of segment QP is = "+len);
}
public void slope(Point O,Point P)
{
double len;
len=(P.y-O.y)/(P.x-O.x);
System.out.println("slope of segment QP is ="+len);
}
}
class ActionPoint
{
public static void main(String as[])
{
Point p1=new Point();
p1.disppoint();
Point p2=new Point(10,10);
p2.disppoint();
Point p3=new Point(5,7);
p3.disppoint();
p1.slope(p1,p2);
p1.length(p1,p2);
p1.slope(p1,p3);
p1.length(p1,p3);
}
}
output:
D:\JavaPrograms\Constructors>javac ActionPoint.java
D:\JavaPrograms\Constructors>java ActionPoint
x: 0 y= 0
x: 10 y= 10
x: 5 y= 7
slope of segment QP is =1.0
length of segment QP is = 14.142135623730951
slope of segment QP is =1.0
length of segment QP is = 8.602325267042627
0 Comments
Post a Comment