point.java

来自「java课件 java课件 java课件 java课件」· Java 代码 · 共 41 行

JAVA
41
字号
public class Point{
  private int x,y;
  public void setX(int x){
    this.x=x;
  }
  public void setY(int y){
    this.y=y;
  }
  public void move(int newX, int newY){
    x = newX ;
    y = newY ;
  }
  public boolean equals(Point p){
    if(x==p.x&&y==p.y)
       return true ;
    else
       return false ;   	
  }
  public Point newPoint(){
    Point temp=new Point();
    temp.x = -x ;
    temp.y = -y ;
    return temp;
  }
  public String toString(){
    return "x="+x+",y="+y ;
  }
  
public static void main(String args[]){
    Point p1 = new Point() ;
    p1.setX(10) ;
    p1.setY(20) ;
    Point p2 = p1.newPoint();
    System.out.println(p1.toString());
System.out.println(p2.toString());
p1.move(100,100);
System.out.println(p1);
    System.out.println(p1.equals(p2)) ;
  }  	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?