Skip to content

Instantly share code, notes, and snippets.

@mayararysia
Created August 21, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayararysia/fa3a926eafd659ea9909b906de18eaba to your computer and use it in GitHub Desktop.
Save mayararysia/fa3a926eafd659ea9909b906de18eaba to your computer and use it in GitHub Desktop.
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