importjava.awt.Color;publicclassPoint{privateintx;privateinty;privateColormycolor;publicPoint(){}publicPoint(intx,inty){this.x=x;this.y=y;}publicPoint(intx,inty,Colormyco...
import java.awt.Color;
public class Point{
private int x;
private int y;
private Color mycolor;
public Point(){
}
public Point(int x,int y){
this.x=x;
this.y=y;
}
public Point(int x,int y,Color mycolor){
this.x=x;
this.y=y;
this.mycolor=mycolor;
}
//从这里开始
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;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;//到这里结束一定要有么,是在定义set和get方法么?
public int distance (Point another){
return (int)Math.sqrt((this.x-another.x)*(this.x-another.x)+(this.y-another.y)*(this.y-another.y));
}
public boolean equals(Point another){
return (this.x==another.x&&this.y==another.y)?true:false;
}
public String toString(){
return "("+x+","+y+")color:"+mycolor;
}
public static void main(String[] args){
Point A=new Point();
Point B=new Point(50,60);
Point C=new Point(100,200,Color.yellow);
System.out.println("B: "+B);
A.setX(100);
A.setY(200);
A.setColor(Color.yellow);
System.out.println("A :"+A);
System.out.println("A==B? "+A.equals(B));
System.out.println("A->B "+A.distance(B));
}
}
展开