程序很简单,可以不考虑其他代码
import java.io.*;
public class Point
{ int a;
int b;
public final static int EAST=1;
public final static int SOUTH=2;
public final static int WEST=3;
public final static int NORTH=4;
public Point(int x,int y) // 将x赋给a, 将y赋给b
{a=x;b=y;}
public Point(){a=0;b=0;} //初始化a,b为0
public Point(Point p) //定义类
{a=p.a; b=p.b;}
public void move(int x,int y)
{a+=x; b+=y;}
public void move(int way)
{
switch(way) //根据输入 way 四种值1,2,3,4(方向),移动坐标x/y
{case 1: a=a+1;
break;
case 2: b=b+1;
break;
case 3: a=a-1;
break;
case 4: b=b-1;
break;}
}
public double Distance(int x;int y)
{ return (Math.sqrt((a-x)*(a-x)+(b-y)*(b-y)));}
public double Distance(Point p)
{return (Math.sqrt((a-p.a)*(a-p.a)+(b-p.b)*(b-p.b)));}
public int getx()
{return (a);}
public int gety()
{return (b);}
public String toString()
{ return ( "( "+a+ ", "+b+ ") ");}
}
class TestPoint
{
public static void main(String[] args)
{
int x,y;
double i,j;
Point m=new Point();
m.move(1,1); //调用前面定义的move(x,y)类,移动位移(x,y)
m.move(3); //调用前面定义的move(x)类,移动方向
i=m.Distance(3,4); //求两点距离
m.toString(); //(a+b)
Point n=new Point(m);
j=n.Distance(m);
n.toString();
x=n.getx();
y=n.gety();
System.out.println( "%d%d ",x,y);