Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started