Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 13, 2019 13:24
Show Gist options
  • Save 0ryant/14784edf7fd645b63f61a841a7f51031 to your computer and use it in GitHub Desktop.
Save 0ryant/14784edf7fd645b63f61a841a7f51031 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Classes; Co-ordinates Distance Calculator
public class Point {
// Params
private int x;
private int y;
// Constructors
public Point() {
this(0,0);
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
// Getters
public int getX() {
return x;
}
public int getY() {
return y;
}
// Setters
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
// Extra Methods
public double distance (){
return distance(0,0);
}
public double distance(int x,int y){
return Math.sqrt(Math.pow(this.x - x, 2) + Math.pow(this.y - y, 2));
}
public double distance(Point newPoint){
return distance(newPoint.x,newPoint.y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment