Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

File 1 : / * * This class represents pairs of integers. * / public class Pair { private int x; private int y; public

File 1:
/**
This class represents pairs of integers.
*/
public class Pair
{
private int x;
private int y;
public Pair()// default constructor
{
this.x =0;
this.y =0;
}
/**
Create a Pair object with the given values.
@param x x-value for the new Pair object
@param y y-value for the new Pair object
*/
public Pair(int 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 Pair(int 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 Pair(Pair p)
{
this.x = p.x;
this.y = p.y;
}
/**
Get the x-value of this Pair object.
@return this Pair's x-value
*/
public int getX()
{
return this.x;
}
/**
Change this Pair object to have the given x-value.
@param x new x-value for this Pair object
*/
public void setX(int x)
{
this.x;
}
/**
Change this Pair object to have the same x-value
as the given Pair.
@param p Pair object whose x-value should be copied
*/
public void setX(Pair p)
{
this.x = p.x;
this.y = p.y;
}
/**
Get the y-value of this Pair object.
@return this Pair's y-value
*/
public int getY()
{
get this.y;
}
/**
Change this Pair object to have the given y-value.
@param y new y-value for this Pair object
*/
public void setY(int y)
{
this.y;
}
/**
Change this Pair object to have the same y-value
as the given Pair.
@param p Pair object whose y-value should be copied
*/
public void setY(Pair p)
{
/
}
/**
Change this Pair object to have the same x-value
and y-value as the given Pair.
@param p Pair object whose x-value and y-value should be copied
*/
public void set(Pair p)
{
// implementation
}
/**
Create a new Pair object that contains the swapped x-value
and y-value from this Pair object.
@return a new Pair that has the swapped values from this Pair
*/
public Pair swap()
{
return new Pair(this.y, this.x);
}
/**
Determine if this Pair object has the same x-value
and the same y-value 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 equals(Pair p)
{
return this.x == p.x && this.y == p.y;
}
/**
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 (2,3) and (3,2)
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 equalNumbers(Pair p)
{
// implementation, not sure what to do
}
public String toString()
{
return "Pair: ("+ x +","+ y +")";
}
}
File 2:
import java.util.Scanner;
public class Tester
{
public static void main(String[] args)
{
final Scanner in = new Scanner(System.in);
final int testCase = in.nextInt();
if (1== testCase)
{
Pair p1= new Pair();
p1.setX(4);
p1.setY(-4);
System.out.println( p1);
Pair p2= new Pair(-5,5);
System.out.println( p2);
Pair p3= new Pair(p2);
System.out.println( p3);
Pair p4= p3.swap();
System.out.println( p3);
System.out.println( p4);
p1.set(p4);
System.out.println( p1);
}
else if (2== testCase)
{
Pair p1= new Pair(2,3);
Pair p2= new Pair(3,2);
System.out.println( p1.equals(p2));
System.out.println( p1.equalNumbers(p2));
System.out.println( p2.equalNumbers(p1));
System.out.println( p1.equals(p2.swap()));
Pair p3= new Pair(8);
System.out.println( p3);
p3.setY(9);
System.out.println( p3);
p3.setX(7);
System.out.println( p3);
Pair p4= new Pair(p1.getX(), p2.getY());
System.out.println( p4);
}
else if (3== testCase)
{
Pair p1= new Pair(4,5);
Pair p2= new Pair(24,25);
System

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

Identify the human resource management functions.

Answered: 1 week ago

Question

Describe who performs human resource management activities.

Answered: 1 week ago