搞了一个小时,还是不能返回值。高手指点一下啊。
题目如下:
实现一个类,描述二维平面的点Point。
描述属性:私有属性
横坐标:double x
纵坐标:double y
实现方法:
二维点的构建;
返回点的横坐标;
返回点的纵坐标;
显示坐标信息,各式:“(x,y)”;
translate(double dx,double dy),移动点:向右移动dx单位,向上移动dy单位;
ratate(double ta),将点沿逆时针方向旋转ta角度
x2 = x1*cos(ta) - y1*sin(ta)
y2 = x1*sin(ta) + y1*cos(ta)
distance(p2)返回该点与点p2的距离;
</b>
下面是我写的程序:
import java.io.*;
import java.math.*;
class Point
{ private double x; //x
private double y;// y
void Point(double a,double b)
{x=a;
y=b;
}
public double getX()//
{ return x;
}
public double getY(){
return y;
}//
public void translate(double dx,double dy)
{x=x+dx;
y=y+dy;
}
public void ratate(double ta)
{ x = x*Math.cos(ta) - y*Math.sin(ta);
y = x*Math.sin(ta) + y*Math.cos(ta);
}
public double distance(Point p2)
{ double temp=Math.pow((x-p2.getX()),2)+Math.pow((y-p2.getY()),2);
return Math.sqrt(temp);
}
void display()
{System.out.println( "the x is : "+x);
System.out.println( "the y is : "+y);
System.out.println( "the number is "+ "( "+x+ ", "+y+ ") ");
}
public static void main(String [] args)
throws
java.io.IOException {String s1,s2,s3,s4,s5,s6,s7;
double a,b,dx,dy,ta,x2,y2;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println( "Enter the value of x: ");
s1=br.readLine();
a=Double.parseDouble(s1);
System.out.println( "Enter the value of y: ");
s2=br.readLine();
b=Double.parseDouble(s2);
Point p1=new Point();
p1.Point(a,b);
p1.display();
System.out.println( "Enter the value of move ! ");
System.out.println( "Enter x: ");
s3=br.readLine();
System.out.println( "Enter y: ");
s4=br.readLine();
dx=Double.parseDouble(s3);