Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * * This class represents pairs of integers. * / public class Pair { private int x; private int y; public Pair ( )
This class represents pairs of integers.
public class Pair
private int x;
private int y;
public Pair default constructor
this.x ;
this.y ;
Create a Pair object with the given values.
@param x xvalue for the new Pair object
@param y yvalue for the new Pair object
public Pairint x int y
x this.x;
y this.y;
Create a Pair object with the given value
as both its x and y values.
@param v value for both numbers in the new Pair object
public Pairint v
v this.x;
Create a Pair object with the same values
as the given Pair object.
@param p Pair object whose values should be copied
public PairPair p
p this. x;
Get the xvalue of this Pair object.
@return this Pair's xvalue
public int getX
return getX;
Change this Pair object to have the given xvalue.
@param x new xvalue for this Pair object
public void setXint x
this.setX x;
Change this Pair object to have the same xvalue
as the given Pair.
@param p Pair object whose xvalue should be copied
public void setXPair p
implementation
Get the yvalue of this Pair object.
@return this Pair's yvalue
public int getY
implementation
Change this Pair object to have the given yvalue.
@param y new yvalue for this Pair object
public void setYint y
implementation
Change this Pair object to have the same yvalue
as the given Pair.
@param p Pair object whose yvalue should be copied
public void setYPair p
implementation
Change this Pair object to have the same xvalue
and yvalue as the given Pair.
@param p Pair object whose xvalue and yvalue should be copied
public void setPair p
implementation
Create a new Pair object that contains the swapped xvalue
and yvalue from this Pair object.
@return a new Pair that has the swapped values from this Pair
public Pair swap
implementation
Determine if this Pair object has the same xvalue
and the same yvalue as the given Pair.
@param p a reference to a second Pair object
@return true if the given Pair is equal to this Pair
public boolean equalsPair p
implementation
Determine if the two numbers in this Pair object are the
same two numbers that are in the given Pair without
regard for the order of the numbers. So and
would have "equal numbers".
@param p a reference to a second Pair object
@return true if this Pair and the other Pair contain the same two numbers
public boolean equalNumbersPair p
implementation
public String toString
return "Pair: x y ;
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