Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyPointTest {
- /** Main method */
- public static void main(String[] args) {
- MyPoint a = new MyPoint (0, 0);
- MyPoint b = new MyPoint (3, 4);
- // Create Distance object
- double d = a.distance(b);
- // Display distance
- System.out.printf(
- "The distance of that point from the origin is %.2f\n",
- d);
- }
- }
- class MyPoint {
- private double x;
- private double y;
- public MyPoint( ) {
- this(0, 0);
- }
- public MyPoint(double x, double y) {
- this.x = x;
- this.y = y;
- }
- 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(MyPoint pointB) {
- return Math.sqrt(Math.pow(pointB.getX - this.getX, 2) + Math.pow(pointB.getY() - this.getY(), 2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement