Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following class, Point.java: In a properly encapsulated class, data attributes are usually set to private so that the client will not be able
Consider the following class, Point.java:
In a properly encapsulated class, data attributes are usually set to private so that the client will not be able to directly access the fields. Make the necessary changes and provide the proper getters and setters.
Add an accessor method called quadrant that returns the number of the quadrant if any in which the called Point object this falls. The method should return:
if both coordinates are positive
if the x coordinate is negative and the y coordinate is positive
if both coordinates are negative
if the x coordinate is positive and the y coordinate is negative
if the point lies on the xaxis or yaxis
For example:
Point p new Point;
pquadrant
Point p new Point;
pquadrant
Point p new Point;
pquadrant
Although most of the methods in a blueprint class are nonstatic meaning that we can think of them as being inside each object of the class they can also include static methods which belong to the class as a whole
A nonstatic method is preferred if the method needs access to the fields of a particular called object. However, if a method does not need a called object ie if it makes more sense to pass in all of the information that it needs as parameters then we typically make it static.
Write a static method closestToOrigin that takes two Point objects and returns the Point that is closest to the origin.
Hint: Make use of the distanceFromOrigin method that every Point has!
Because the method is static, we must prepend the class name to call it from outside the class:
Point p new Point;
Point p new Point;
Point.closestToOriginp p
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