Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Write a class , Point, to represent a 2-dimensional point with coordinates x and y (both doubles). Your class should contain the following instance

image text in transcribed

image text in transcribed

1) Write a class , Point, to represent a 2-dimensional point with coordinates x and y (both doubles). Your class should contain the following instance variables and methods, override toString() and equals(), and implement the comparable interface. private double x private double y public Point () public Point (double x, double y) public void setx (double x) public void sety (double y) public double getX() public double getY() public double distance (Point p) the x coordinate the y coordinate constructs the point(0, 0) constructs a point with the given coordinates sets the x coordinate to the given value sets the y coordinate to the given value returns the x coordinate returns the y coordinate returns the distance from another point Two points are equal if they have the same x coordinates and the same y coordinates. When implementing Comparable, points should be compared relative to their distance from the origin (0,0), with points closer to the origin considered less than points farther from it. The distance between two points is defined as the square root of the sum of the squares of the differences between the x and y coordinates. Below is the distance formaula: d= (x2 21)2 + (y2 y)2 Use Javadoc comments including @param and @return. Your answer 2) Consider the point class you wrote in question #1. The following code produces 4 lines of output. Write each line of output below as it would appear on the screen. public class Question2 { public static void main (String[] args) { int a = 3; int b = 6; Point pl = new Point (2,2); Point p2 = new Point (2,2); addTwice (a, pl); System.out.println(a + + pl.getX() addTwice (b, p2); System.out.println(a + + pl.getX() + "" } + 1 + p2.getX()); TI 11 + p2.getX()); public static void addTwice (int a, Point pl) { a = a + a; p1.setX (a); System.out.println(a + + pi.getX(); } } Your

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions