Skip to content

Instantly share code, notes, and snippets.

@yrchen
Forked from litopon/MyPoint.java
Created March 20, 2012 09:54
Show Gist options
  • Save yrchen/2133620 to your computer and use it in GitHub Desktop.
Save yrchen/2133620 to your computer and use it in GitHub Desktop.
Code Solution of Assignment #4-2
package a4.s100522092;
public class MyPoint {
private double x;
private double y;
public MyPoint(){
}
public MyPoint(double x_input, double y_input){ // constructor to initial private data member
x = x_input;
y = y_input;
}
public double getX(){ // return x value
return x;
}
public double getY(){ // return y value
return y;
}
public void setX(double input) // set x value
{
x = input;
}
public void setY(double input) // set y value
{
y = input;
}
public double distance(MyPoint input){ // the distance between this point and the input point
return Math.sqrt((x - input.getX())*(x - input.getX()) + (y - input.getY())*(y - input.getY()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment