Answered step by step
Verified Expert Solution
Question
1 Approved Answer
File 1 : / * * This class represents pairs of integers. * / public class Pair { private int x; private int y; public
File :
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
this.x x;
this.y 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
this.x v;
this.y v;
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
this.x px;
this.y py;
Get the xvalue of this Pair object.
@return this Pair's xvalue
public int getX
return this.x;
Change this Pair object to have the given xvalue.
@param x new xvalue for this Pair object
public void setXint x
this.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
this.x px;
this.y py;
Get the yvalue of this Pair object.
@return this Pair's yvalue
public int getY
get this.y;
Change this Pair object to have the given yvalue.
@param y new yvalue for this Pair object
public void setYint y
this.y;
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
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
return new Pairthisy this.x;
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
return this.x px && this.y py;
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, not sure what to do
public String toString
return "Pair: x y ;
File :
import java.util.Scanner;
public class Tester
public static void mainString args
final Scanner in new ScannerSystemin;
final int testCase innextInt;
if testCase
Pair p new Pair;
psetX;
psetY;
System.out.println p;
Pair p new Pair;
System.out.println p;
Pair p new Pairp;
System.out.println p;
Pair p pswap;
System.out.println p;
System.out.println p;
psetp;
System.out.println p;
else if testCase
Pair p new Pair;
Pair p new Pair;
System.out.println pequalsp;
System.out.println pequalNumbersp;
System.out.println pequalNumbersp;
System.out.println pequalspswap;
Pair p new Pair;
System.out.println p;
psetY;
System.out.println p;
psetX;
System.out.println p;
Pair p new PairpgetX pgetY;
System.out.println p;
else if testCase
Pair p new Pair;
Pair p new Pair;
System
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