Question: Problem #1. (UML Diagram) -------------------------------------------------- Point -------------------------------------------------- -x: int -y: int -------------------------------------------------- + Point() + Point(xVal: int, yVal: int) + getX(): int + getY(): int

Problem #1.

(UML Diagram)

--------------------------------------------------

Point

--------------------------------------------------

-x: int

-y: int

--------------------------------------------------

+ 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 new X and new Y 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 typePoint, the method returns the distance (a double value) from the (x, y)- location of the Point Object2 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:

vision an exponent (xV1-xV2)^2+(yV1-yV2)^2

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

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!