Answered step by step
Verified Expert Solution
Link Copied!

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:image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

=+What is our leadership style like?

Answered: 1 week ago