Question: public class pointJava { public static void main (String [] args) { //create two point objects Point p1 = new Point (); p1.x = 7;

public class pointJava {

public static void main (String [] args) {

//create two point objects

Point p1 = new Point ();

p1.x = 7;

p1.y = 8;

Point p2 = new Point ();

p2.x = 4;

p2.y = 3;

//Print each point and its distance from the origin

System.out.println (p1);

System.out.println (p2);

System.out.println (p1.distanceFromOrigin());

// print the distance between p1 and p2

System.out.println (p1.distance (p2));

}

}

Add the following methods to the program:

  • Write a method setLocation that changes a Point's location to the (x, y) values passed.
  • Write a method translate that changes a Point's location by a given dx, dy amount.
  • Write a method distance that computes the distance between a Point and another Point parameter.

    Use the formula:public class pointJava { public static void main (String [] args) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!