Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(All Code in JAVA please) : Create a Point class. The class should contain 2 fields (integers called x and y, for the x and

(All Code in JAVA please) :

Create a Point class. The class should contain 2 fields (integers called x and y, for the x and y coordinates, positive values) and the following methods:

-Default and alternate constructors.

-Two getters (accessors) to return the x and y coordinates

-A method named set to set the coordinates to the parameters passed? invalid values set to 0

-A method named print to print each Point object as (x, y)

-A method toString()

-A method named equals to compare 2 Point objects for equality 2 methods named copy and getCopy to make a copy of a Point object into another Point object

-A method named distanceFromOrigin to calculate the distance between a point and the origin at(0, 0)

-A method named distance to calculate the distance from a point to a given point.

-A method named translate to shift the location of a point by a given amount.

-A method named isHorizontal that returns true if any given point lines up horizontally with a given point.

-A method named isVertical that returns true if any given Point object lines up vertically with a given Point object.

-A method named slope that returns the slope of the line between this Point object and a given Point object.

Task 2: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below:

---After declaration, constructors invoked ---Using toString():

First point is (0, 0)

Second point is (7, 13)

Third point is (7, 15)

Second point (7, 13) lines up vertically with third point (7, 15)

Second point (7, 13) doesn't line up horizontally with third point (7, 15)

Enter the x-coordinate for first point: retgre

Not an integer! Try again! Enter the x-coordinate for first point: 89.67

Not an integer! Try again! Enter the x-coordinate for first point: -13

ERROR! Should be positive. Enter the xcoordinate for first point: -15

Enter the y-coordinate for first point: fwgfe

Not an integer! Try again! Enter the y-coordinate for first point: 90.6

Not an integer! Try again! Enter the y-coordinate for first point: -32

ERROR! Should be positive. Enter the y-coordinate for first point: b

Not an integer! Try again! Enter the ycoordinate for first point: 23

First point (after call to set) is (15, 23)

Distance from origin for first point = 27.46

Distance from origin for second point = 14.76

Distance between first point and second point = 12.81

First point (after call to translate (5, 10)) is (20, 33)

Second point (after call to translate (15, 5)) is (22, 18)

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

Students also viewed these Databases questions

Question

Exposure to SQL desirable but not required

Answered: 1 week ago

Question

Strong analytical, communication, and problem-solving skills

Answered: 1 week ago