?? mypoint.java
字號:
//Exercise 7.4
public class MyPoint {
//variables
private int x;
private int y;
//constructors
public MyPoint(){//no args to initialize a point(0,0)
x = 0;
y = 0;
}
public MyPoint(int x, int y){//constructs a point with the specified x and y co‐ordinates
this.x = x;
this.y = y;
}
//getters and setters
public int getX(){
return x;
}
public void setX(int x){
this.x = x;
}
public int getY(){
return y;
}
public void setY(int y){
this.y = y;
}
//methods
public double distance(int x, int y){
return Math.sqrt((this.x - x)*(this.x - x)+ (this.y - y)*(this.y - y) );
}
public double distance(MyPoint another){
return Math.sqrt((x - another.x)*(x - another.x)+ (y - another.y)*(y - another.y));
}
//toString
public String toString(){
return "the point is ("+ x +"," + y +").";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -