Problem 2: - x: int -y: int Point + Point() + Point (xVal: int, yVal: int) + getX(): int + getY(): int + setpoint (newX: int, newY: int): void + toString(): String + distance (Point pnt): double. Given the UML diagram above, complete the Point class that models a point on a Cartesian plane, the class should have the following instance variables, constructor(s) and instance methods: Two private integer instance variables, x and y. A "no-arg" constructor that creates a point with the coordinates (0, 0). An overloaded constructor that takes two integer parameters xVal and yVal and set the instance variables accordingly. A getter method for each instance variable. A method named setPoint that takes two integer parameters newx and newY and set the instance variables accordingly. A method named toString which takes no parameters, and returns a string with the coordinates of the point within parentheses and comma separated, for example: (2, 5) A method named distance which takes one class parameter of type Point, the method returns the distance (a double value) from the (x, y)-
Problem 2: - x: int -y: int Point + Point() + Point (xVal: int, yVal: int) + getX(): int + getY(): int + setpoint (newX: int, newY: int): void + toString(): String + distance (Point pnt): double. Given the UML diagram above, complete the Point class that models a point on a Cartesian plane, the class should have the following instance variables, constructor(s) and instance methods: Two private integer instance variables, x and y. A "no-arg" constructor that creates a point with the coordinates (0, 0). An overloaded constructor that takes two integer parameters xVal and yVal and set the instance variables accordingly. A getter method for each instance variable. A method named setPoint that takes two integer parameters newx and newY and set the instance variables accordingly. A method named toString which takes no parameters, and returns a string with the coordinates of the point within parentheses and comma separated, for example: (2, 5) A method named distance which takes one class parameter of type Point, the method returns the distance (a double value) from the (x, y)-
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question

Transcribed Image Text:Problem 2:
- x: int
- y: int
Point
+ Point ()
+ Point (xVal: int, yVal: int)
+ getX(): int
+ getY(): int
+ setpoint (newX: int, newY: int): void
+ toString(): String
+ distance (Point pnt): double
Given the UML diagram above, complete the Point class that models a point on a
Cartesian plane, the class should have the following instance variables,
constructor(s) and instance methods:
Two private integer instance variables, x and y.
A "no-arg" constructor that creates a point with the coordinates (0, 0).
An overloaded constructor that takes two integer parameters xVal and
yVal and set the instance variables accordingly.
A getter method for each instance variable.
A method named setPoint that takes two integer parameters newX and
newY and set the instance variables accordingly.
A method named toString which takes no parameters, and returns a
string with the coordinates of the point within parentheses and comma
separated, for example: (2, 5)
A method named distance which takes one class parameter of type
Point, the method returns the distance (a double value) from the (x, y)-

Transcribed Image Text:location of the Point object that calls the method to the (x, y)-location of
the Point object passed in.
The distance between two point is calculated by the formula:
√(x₁ - x₂)² + (y₁ - y₂)²
=
Hints:
Use Math.pow(n, 2) to raise a number to a power.
Use Math.sqrt(number) to find the square root of a number.
Your output should look exactly the same as follows:
The distance from (0, 0) to (3, 4) is: 5.0
P1 new coordinates are:
X = 1
y = 4
P2 new coordinates are:
X = 2
y
3
The distance from (1, 4) to (2, 3) is: 1.4142135623730951
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY