⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mypoint.java

📁 tutorial for java programming
💻 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 + -