Created
August 21, 2020 14:44
-
-
Save mayararysia/fa3a926eafd659ea9909b906de18eaba to your computer and use it in GitHub Desktop.
An example of a class Coordinate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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