2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 定义一个描述平面坐标系统中点及其操作的类Point.(Java)定义一个描述平面坐标系统中的

定义一个描述平面坐标系统中点及其操作的类Point.(Java)定义一个描述平面坐标系统中的

时间:2020-04-08 13:47:00

相关推荐

定义一个描述平面坐标系统中点及其操作的类Point.(Java)定义一个描述平面坐标系统中的

问题补充:

定义一个描述平面坐标系统中点及其操作的类Point.(Java)定义一个描述平面坐标系统中的点及其操作的类Point.它有两个double型私有属性x和y描述点在坐标轴中的位置.该类还包含如下方法:初始化x和y的构造函数;返回x和y值的方法getX( )和getY( );将给定坐标平移w(水平)和h(垂直)的方法shiftPoint(double w,double h);判断调用该方法的点的坐标和

答案:

public class Point {

private double x;

private double y;

public Point(double x, double y){

this.x = x;

this.y = y;

} public double getX() {

return x;

} public double getY() {

return y;

} public void shiftPoint(double w, double h){

x += w; y += y; } public boolean pointEquals(Point point){

if(point.x == x && point.y == y)

return true;

return false;

} public void whatQuadrant(){

int a = 1;

if( x 0)

a = 2; else if(x a = 3; else if(x >0 && y a = 4; if( x == 0 && y == 0 )

System.out.println(点(+x+,+y+)在原点);

else if(x == 0 && y !=0 )

System.out.println(点(+x+,+y+)在Y轴);

else if( y == 0 && x != 0 )

System.out.println(点(+x+,+y+)在X轴);

else System.out.println(点(+x+,+y+)在第+a+象限);

} public double findDistance(Point p){

BigDecimal b = new BigDecimal(Double.toString(Math.sqrt(Math.pow(x - p.x, 2) + Math.pow(y - p.y, 2))));

return b.setScale(2, BigDecimal.ROUND_CEILING).doubleValue();

} public String toString(){

return (+x+,+y+);

} public static void main(String [] args){

Point p =new Point(3,2);

System.out.println(x=+p.getX()+y=+p.getY());

p.pointEquals(new Point(3,2));

p.shiftPoint(5,6);

System.out.println(x=+p.getX()+y=+p.getY());

p.whatQuadrant();

System.out.println(p.findDistance(new Point(0,0)));

System.out.println(p.toString());

}}

定义一个描述平面坐标系统中点及其操作的类Point.(Java)定义一个描述平面坐标系统中的点及其操

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。