-
-
Save yrchen/2133620 to your computer and use it in GitHub Desktop.
Code Solution of Assignment #4-2
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
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