我是JAVA的初学者,有道题不会,哪位大哥帮个忙吧!

2025-01-27 13:33:46
推荐回答(1个)
回答1:

/*
* Point.java
*
* Created on 2007��4��14��, ����8:23
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author idle~
*/
public class Point {

private double x = 0.0;
private double y = 0.0;
/** Creates a new instance of Point
* @param x
* @param y
*/
public Point(double x,double y) {
this.x = x;
this.y = y;
}

public double getX(){
return x;
}

public double getY(){
return y;
}

/**
*
* @param w
* @param h
*/
public void shiftPoint(double w,double h){
x += w;
y += h;
}

public boolean pointEquals(Point p){
if(this.getX() == p.getX() && this.getY() == p.getY())
return true;
else
return false;
}

public String whatQuadrant(){
if(this.x > 0 && this.y > 0 ){
return "first quadrant";
}else if(this.x > 0 && this.y < 0){
return "fourth quadrant";
}else if(this.x < 0 && this.y > 0){
return "second quarant";
}else
return "third quarant";
}

public double findDistance (Point p){
double m = this.x - p.getX();
double n = this.y - p.getY();
return Math.sqrt(m * m + n * n);
}

public String toString(){
return "(" + this.x + "," + this.y + ")";
}
}