Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An example of a class Coordinate
import java.lang.Math;
public class Coordinate {
// attributes
private Double x;
private Double y;
// constructor
// defined how to create an instance of this class
public Coordinate(Double x, Double y) {
this.x = x;
this.y = y;
}
// methods
public Double getX() {
return x;
}
public void setX(Double x) {
this.x = x;
}
public Double getY() {
return y;
}
public void setY(Double y) {
this.y = y;
}
public Double distance(Coordinate coordinate){
Double abscissas = Math.pow((this.x - coordinate.x), 2);
Double ordinates = Math.pow((this.y - coordinate.y), 2);
return Math.pow((abscissas + ordinates), 0.5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment