Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students explore these related Databases questions