永发信息网

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

答案:2  悬赏:50  手机版
解决时间 2021-02-28 05:47
  • 提问者网友:且恨且铭记
  • 2021-02-27 08:34
定义一个描述平面坐标系统中点及其操作的类Point.(Java)定义一个描述平面坐标系统中的点及其操
最佳答案
  • 五星知识达人网友:慢性怪人
  • 2021-02-27 08:52
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()); }}
全部回答
  • 1楼网友:孤老序
  • 2021-02-27 09:47
就是这个解释
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯