Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started