Question: Java 1. Task: Create a Point class. The class should contain 2 fields (integers called x and y, for the x and y coordinates, positive

Java

1. Task: 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.

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!